update on machine learning
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from IPython.display import display
|
||||
import sklearn
|
||||
from sklearn.linear_model import LinearRegression
|
||||
from sklearn.tree import DecisionTreeRegressor
|
||||
from sklearn.model_selection import train_test_split
|
||||
X_train, X_test, y_train, y_test = train_test_split(x, y, random_state=0)
|
||||
|
||||
data = np.loadtxt('src/Hudson_Bay.csv', delimiter=',', skiprows=1)
|
||||
x = data[:,0]
|
||||
y = data[:,1]
|
||||
x_train, y_train = train_test_split(x, y, random_state=0)
|
||||
line = np.linspace(1900,1930,1000,endpoint=False).reshape(-1,1)
|
||||
reg = DecisionTreeRegressor(min_samples_split=3).fit(x.reshape(-1,1),y.reshape(-1,1))
|
||||
plt.plot(line, reg.predict(line), label="decision tree")
|
||||
regline = LinearRegression().fit(x.reshape(-1,1),y.reshape(-1,1))
|
||||
plt.plot(line, regline.predict(line), label= "Linear Regression")
|
||||
plt.plot(x, y, label= "Linear Regression")
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user