亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問為什么畫出來的圖沒有x,y軸坐標含義?且沒有圖例

請問為什么畫出來的圖沒有x,y軸坐標含義?且沒有圖例

qq_01_15 2018-05-24 14:42:06
# -*- coding: utf-8 -*-"""Created on Tue May 22 15:56:56 2018@author: dell"""import numpy as npclass Perceptron(object):? ? def __init__(self,eta=0.01,n_iter=10):? ? ? ? self.eta=eta;? ? ? ? self.n_iter=n_iter? ? ? ? pass? ? def fit(self,X,y):? ? ? ? self.w_=np.zero(1+x.shape[1]);? ? ? ? self.errors_=[]? ? ? ? for _ in range(self,n_iter):? ? ? ? ? ? errors_=0? ? ? ? ? ? for Xi,target in zip(x,y):? ? ? ? ? ? ? ? update=self.eta*(target-self.predict(Xi))? ? ? ? ? ? ? ? self.w_[1:]+=update*Xi? ? ? ? ? ? ? ? self.w_[0]+=update;? ? ? ? ? ? ? ? errors+=int(update!=0.0)? ? ? ? ? ? ? ? self.errors_.append(errors)? ? ? ? ? ? ? ? pass? ? ? ? ? ? pass? ? def net_input(self,X):? ? ? ? return np.dot(x,self.w_[1:])+self.w_[0]? ? ? ? pass? ? def predict(self,x):? ? ? ? return np.where(self.net_input(x)>=0.0,1,-1)? ? ? ? pass? ? passfile="iris.date.csv.txt"import pandas as pddf=pd.read_csv(file,header=None)import matplotlib.pyplot as pltimport numpy as npy=df.loc[:100,4].valuesy=np.where(y=='Iris-setosa',-1,1)print (y)X=df.iloc[:100,[0,2]].valuesprint (X)plt.scatter(X[:50,0],X[:50,1],color='red',marker='o',label='setosa')plt.scatter(X[50:100,0],X[50:100,1],color='blue',marker='x',label='versicolor')plt.xlabel('花瓣長度')plt,ylabel('花徑長度')?plt,legend(loc='upper left')plt.show() ??請問為什么畫出來的圖沒有x,y軸坐標含義?且沒有圖例學習視頻里面畫出的圖是這樣的我卻弄不出來
查看完整描述

1 回答

?
Yexiaomo

TA貢獻152條經驗 獲得超157個贊

你的程序不是已經提示出錯了嗎

https://img1.sycdn.imooc.com//5cd03d5f0001597507880142.jpg

是plt.ylabel('花莖長度')
不是plt,ylabel('花莖長度')?#調用函數不是逗號,是點


查看完整回答
反對 回復 2019-05-06
  • 1 回答
  • 0 關注
  • 1524 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號