機器學習相關問題與資源下載。
阿新 • • 發佈:2018-12-13
1、執行如下程式碼:
import numpy from numpy import * import matplotlib.pyplot as plt dataset = [[-0.017612,14.053064],[-1.395634,4.662541],[-0.752157,6.538620],[-1.322371,7.152853], [0.423363,11.054677],[0.406704,7.067335],[0.667394,12.741452],[-2.460150,6.866805], [0.569411,9.548755],[-0.026632,10.427743],[0.850433,6.920334],[1.347183,13.175500], [1.176813,3.167020],[-1.781871,9.097953]] dataMat = mat(dataset).T plt.scatter(dataMat[0], dataMat[1], c='red', marker='o') X = numpy.linspace(-2, 2, 100) Y = 2.8*X+9 plt.plot(X, Y) plt.show()
報錯:ValueError: Masked arrays must be 1-D
解決方法:
將語句:plt.scatter(dataMat[0], dataMat[1], c=‘red’, marker=‘o’)
改為:plt.scatter(dataMat[0].tolist(), dataMat[1].tolist(), c='red', marker='o')