-
Notifications
You must be signed in to change notification settings - Fork 3
/
GuessTheDollars
106 lines (56 loc) · 1.85 KB
/
GuessTheDollars
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#! /usr/bin/env python
# -*- coding: UTF-8 -*-
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
import matplotlib.pyplot as plt
from sklearn.preprocessing import PolynomialFeatures
veri = pd.read_csv("2016dolaralis.csv")
x = veri["Gun"]
y = veri["Fiyat"]
x = x.reshape(18,1)
y= y.reshape(18,1)
plt.scatter(x,y)
plt.show()
#Lineer Reg.
tahminlineer = LinearRegression()
tahminlineer.fit(x,y)
tahminlineer.predict(x)
plt.plot(x,tahminlineer.predict(x),c="red")
#Polinom Reg.
tahminpolinom = PolynomialFeatures(degree=3)
Xyeni = tahminpolinom.fit_transform(x)
polinommodel = LinearRegression()
polinommodel.fit(Xyeni,y)
polinommodel.predict(Xyeni)
plt.plot(x,polinommodel.predict(Xyeni))
plt.show()
hatakaresilineer = 0
hatakaresipolinom = 0
for i in range(len(Xyeni)):
hatakaresipolinom = hatakaresipolinom + (float(y[i])-float(polinommodel.predict(Xyeni)[i]))**2
for i in range(len(y)):
hatakaresilineer = hatakaresilineer + (float(y[i])-float(tahminlineer.predict(x)[i]))**2
print(hatakaresilineer)
print(hatakaresipolinom)
"""
hatakaresipolinom = 0
for a in range(150):
tahminpolinom = PolynomialFeatures(degree=a+1)
Xyeni = tahminpolinom.fit_transform(x)
polinommodel = LinearRegression()
polinommodel.fit(Xyeni,y)
polinommodel.predict(Xyeni)
for i in range(len(Xyeni)):
hatakaresipolinom = hatakaresipolinom + (float(y[i])-float(polinommodel.predict(Xyeni)[i]))**2
print(a+1,"inci dereceden fonksiyonda hata,", hatakaresipolinom)
hatakaresipolinom = 0
"""
tahminpolinom8 = PolynomialFeatures(degree=3)
Xyeni = tahminpolinom8.fit_transform(x)
polinommodel8 = LinearRegression()
polinommodel8.fit(Xyeni,y)
polinommodel8.predict(Xyeni)
plt.plot(x,polinommodel8.predict(Xyeni))
plt.show()
print((float(y[201])-float(polinommodel8.predict(Xyeni)[201])))