runze-预测鸢尾花

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)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值