教師あり、教師なし

教師あり学習: 正解ラベルの付いたデータセット
教師なし学習: 正解ラベルの付いていないデータセット
-> 人間の解釈が必要な場合が多い

import numpy as np 
import matplotlib.pyplot as plt 
%matplotlib inline

from sklearn import datasets 
iris = datasets.load_iris()

print(iris.DESCR)
import numpy as np 
import numpy.random as random 
import scipy as sp 
import pandas as pd 
from pandas import Series, DataFrame 

from sklearn.model_selection import train_test_split 
from sklearn.datasets import load_iris 

iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df["target"] = iris.target_names[iris.target]

df.head()

X = df.drop('target', axis=1)
Y = df['target']

X_train, X_test, y_train, y_test = train_test_split(X,Y,random_state=0)

# K-NN
from sklearn.neighbors import KNeighborsClassifier 
model = KNeighborsClassifier(n_neighbors=3)
model.fit(X_train, y_train)

print("train score:",model.score(X_train,y_train))
print("test score:",model.score(X_test,y_test))

# decision tree
from sklearn.tree import DecisionTreeClassifier 
model = DecisionTreeClassifier(max_depth=3)
model.fit(X_train, y_train)

print("train score:",model.score(X_train,y_train))
print("test score:",model.score(X_test,y_test))

# SVM
from sklearn.svm import LinearSVC
model = LinearSVC()
model.fit(X_train, y_train)

print("train score:",model.score(X_train,y_train))
print("test score:",model.score(X_test,y_test))

# Linear Regression
from sklearn.linear_model import LogisticRegression

model = LogisticRegression()
model.fit(X_train, y_train)

print("train score:",model.score(X_train,y_train))
print("test score:",model.score(X_test,y_test))