Time_series_prediction

Last updated: August 29th, 20202020-08-29Project preview
In [5]:
pip install scikit-fuzzy
Collecting scikit-fuzzy
  Downloading scikit-fuzzy-0.4.2.tar.gz (993 kB)
     |████████████████████████████████| 993 kB 24.0 MB/s eta 0:00:01
Requirement already satisfied: numpy>=1.6.0 in /usr/local/lib/python3.8/site-packages (from scikit-fuzzy) (1.18.1)
Requirement already satisfied: scipy>=0.9.0 in /usr/local/lib/python3.8/site-packages (from scikit-fuzzy) (1.4.1)
Collecting networkx>=1.9.0
  Downloading networkx-2.4-py3-none-any.whl (1.6 MB)
     |████████████████████████████████| 1.6 MB 38.7 MB/s eta 0:00:01
Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.8/site-packages (from networkx>=1.9.0->scikit-fuzzy) (4.4.2)
Building wheels for collected packages: scikit-fuzzy
  Building wheel for scikit-fuzzy (setup.py) ... done
  Created wheel for scikit-fuzzy: filename=scikit_fuzzy-0.4.2-py3-none-any.whl size=894068 sha256=2cea4c6f90671d63ba082096e95c3c5ca7089e09a99a6144f7c0bbf0bcf536cc
  Stored in directory: /root/.cache/pip/wheels/2c/04/80/7eefb1a2de7d36aefd06432fab2a1486caf0a0596a7067391a
Successfully built scikit-fuzzy
Installing collected packages: networkx, scikit-fuzzy
Successfully installed networkx-2.4 scikit-fuzzy-0.4.2
WARNING: You are using pip version 20.0.2; however, version 20.2.2 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Note: you may need to restart the kernel to use updated packages.
In [39]:
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

# New Antecedent/Consequent objects hold universe variables and membership
# functions
quality = ctrl.Antecedent(np.arange(0, 11, 1), 'quality')
service = ctrl.Antecedent(np.arange(0, 11, 1), 'service')
tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')

# Auto-membership function population is possible with .automf(3, 5, or 7)
quality.automf(3)
service.automf(3)

# Custom membership functions can be built interactively with a familiar,
# Pythonic API
tip['low'] = fuzz.trimf(tip.universe, [0, 0, 13])
tip['medium'] = fuzz.trimf(tip.universe, [0, 13, 25])
tip['high'] = fuzz.trimf(tip.universe, [13, 25, 25])
In [40]:
# You can see how these look with .view()
quality['average'].view()
In [9]:
service.view()
In [10]:
tip.view()
In [11]:
rule1 = ctrl.Rule(quality['poor'] | service['poor'], tip['low'])
rule2 = ctrl.Rule(service['average'], tip['medium'])
rule3 = ctrl.Rule(service['good'] | quality['good'], tip['high'])

rule1.view()
Out[11]:
(<Figure size 432x288 with 1 Axes>,
 <matplotlib.axes._subplots.AxesSubplot at 0x7f3ad9835f10>)
In [19]:
from math import log2

def distance_r(t_N, t_M):
    return log2(abs(t_N - t_M))
In [20]:
print(distance_r(10,5))
2.321928094887362
In [106]:
import numpy as np
import skfuzzy as fuzz
from skfuzzy import control as ctrl

# New Antecedent/Consequent objects hold universe variables and membership
# functions
p = ctrl.Antecedent(np.arange(0, 5, 1), 'p')
q = ctrl.Antecedent(np.linspace(0, 1, 6000), 'q')
#tip = ctrl.Consequent(np.arange(0, 26, 1), 'tip')

# Custom membership functions can be built interactively with a familiar,
# Pythonic API
p['P1'] = fuzz.trimf(p.universe, [0, 0, 1])
p['P2'] = fuzz.trimf(p.universe, [0, 1, 2])
p['P3'] = fuzz.trimf(p.universe, [1, 2, 3])
p['P4'] = fuzz.trimf(p.universe, [2, 3, 4])
p['P5'] = fuzz.trimf(p.universe, [3, 4, 4])

q['Q1'] = fuzz.trapmf(q.universe, [0, 0, .1, .2])
q['Q2'] = fuzz.trimf(q.universe, [.1, .2, .3])
q['Q3'] = fuzz.trimf(q.universe, [.2, .4, .6])
q['Q4'] = fuzz.trimf(q.universe, [.3, .6, .9])
q['Q5'] = fuzz.trimf(q.universe, [.7, .8, .9])
q['Q6'] = fuzz.trapmf(q.universe, [.8, .9, 1, 1])
In [107]:
p.view()
q.view()
Notebooks AI
Notebooks AI Profile20060