import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sklearn
from sklearn import datasets
from sklearn.model_selection import train_test_split
np.set_printoptions(precision=3) # 出力値(ndarray)の桁数を指定
iris = datasets.load_iris()
datas, target = iris.data, iris.target
df_data = pd.DataFrame(datas, columns=iris.feature_names)
x_train, x_test, y_train, y_test = train_test_split(datas, target, test_size=0.2, random_state=0) # 学習データとテストデータへ7:3で分割
print(x_train.shape, x_test.shape, y_train.shape, y_test.shape)
from sklearn.linear_model import LinearRegression
model_lin = LinearRegression()
model_lin.fit(x_train,y_train)
y_pred = model_lin.predict(x_test)
model_lin.score(x_test, y_test)
model_lin.coef_
from sklearn.linear_model import LogisticRegression
logit = LogisticRegression(max_iter=1000)
logit.fit(x_train, y_train)
y_pred = logit.predict(x_test)
logit.score(x_test, y_test)
y_pred
weight= np.array([[-0.394, 0.851, -2.36 , -1.012],
[ 0.41 , -0.319, -0.146, -0.788],
[-0.016, -0.532, 2.506, 1.8 ]])
bias = np.array([ 9.273, 2.317, -11.59 ])
x = x_test[0]
y = weight@x+bias
y_softmax = np.exp(y)/np.exp(y).sum()