from sklearn import datasets
import matplotlib.pyplot as plt
plt.rcParams["font.sans-serif"] = ["SimHei"]
flower_data = datasets.load_iris()
print(flower_data)
# 网络 github
# 花萼长度 花萼宽度 花瓣长度 花瓣宽度
# 0 山鸢尾花 1变色鸢尾花 2 维吉尼亚鸢尾花
import pandas as pd
flower = pd.DataFrame(flower_data.data)
flower_species = pd.DataFrame(flower_data.target)
df = pd.concat([flower,flower_species],axis=1)
df.columns = ["花萼长度","花萼宽度","花瓣长度","花瓣宽度","种类"]
x = "花瓣长度"
y = "花瓣宽度"
plt.scatter(df[x][0:49], df[y][0:49],color="blue",label="山鸢尾花")
plt.scatter(df[x][50:99],df[y][50:99],color="green",label="变色鸢尾花")
plt.scatter(df[x][100:149], df[y][100:149],color="black",label="维吉尼亚鸢尾花")
plt.xlabel(x)
plt.ylabel(y)
plt.legend() # 图例
plt.show()
from sklearn import linear_model as lm
import numpy as np
predict_flower = np.asarray([[3,4,1,0.2],[5,2,4,1] ])
model = lm.LinearRegression()
model.fit(flower,flower_species)
hua = model.predict(predict_flower)
print(hua)
score = model.score(flower,flower_species)
print(score)
from sklearn.linear_model import LogisticRegression as lg
model1 = lg()
model1.fit(flower,flower_species)
hua1 = model1.predict(predict_flower)
print(hua1)
score1 = model1.score(flower,flower_species)
print(score1)
runze-预测鸢尾花
最新推荐文章于 2022-12-05 17:52:16 发布