sklearn linear_model,svm,tree,naive bayes,ensemble by iris dataset
In [15]:
from sklearn import datasets
import numpy as np
from sklearn.model_selection import train_test_split
iris =datasets.load_iris()
# print(iris.data)
X = iris.data[:,[2,3]]
y =iris.target
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.3,random_state=0)
print(X_train.shape,y_train.shape,X_test.shape,y_test.shape)
print(X_train,y_train,X_test,y_test)
In [61]:
from sklearn.model_selection import train_test_split
from sklearn import datasets
import numpy as pn
from sklearn.linear_model import LogisticRegression
from sklearn.linear_model import LinearRegression
from sklearn.svm import SVR
from sklearn.svm import SVC
from sklearn.tree import DecisionTreeRegressor
from sklearn.naive_bayes import GaussianNB
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import RandomForestRegressor
import matplotlib.pyplot as plt
iris = datasets.load_iris()
X = iris.data[:,[2,3]]
y = iris.target
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size =0.3,random_state=0)
print(X_train.shape,y_train.shape,X_test.shape,y_test)
logreg = LogisticRegression()
logreg.fit(X_train,y_train)
print(logreg.score(X_test,y_test))
linear = LinearRegression()
linear.fit(X_train,y_train)
print(linear.score(X_test,y_test))
decisiont = DecisionTreeRegressor()
decisiont.fit(X_train,y_train)
print(decisiont.score(X_test,y_test))
res =decisiont.predict([[3.2,1]])
print(res)
nb = GaussianNB()
nb.fit(X_train,y_train)
print(nb.score(X_test,y_test))
print(nb.predict([[3.2,1]]))
rd = RandomForestClassifier()
rd.fit(X_train,y_train)
print(rd.score(X_test,y_test))
rr = RandomForestRegressor()
rr.fit(X_train,y_train)
print(rr.score(X_test,y_test))
svm = SVC()
svm.fit(X_train,y_train)
print(svm.score(X_test,y_test))
svr = SVR()
svr.fit(X_train,y_train)
print(svr.score(X_test,y_test))
plt.plot(X_test)
plt.show()
In [ ]: