Ich folge in einem ML-Lehrbuch: Mastering Machine Learning mit scikit-lernen, und während mein Code mir die richtigen Antworten gibt, tut es nicht Passt zu dem, was in dem Buch steht.Zeigen Sie eine Zeile in Matplotlib, so dass meine Ergebnisse mit meinem Lehrbuch übereinstimmen
Zuerst gibt es mir diesen Code:
import matplotlib.pyplot as plt
X = [[6], [8], [10], [14], [18]]
y = [[7], [9], [13], [17.5], [18]]
plt.figure()
plt.title('Pizza price plotted against diameter')
plt.xlabel('Diameter in inches')
plt.ylabel('Price in dollars')
plt.plot(X, y, 'k.')
plt.axis([0, 25, 0, 25])
plt.grid(True)
plt.show()
Was mir diese Grafik in matplotlib gibt:
Und das paßt mit meinen Ergebnissen.
jedoch im nächsten Schritt gibt mir diesen Code:
from sklearn.linear_model import LinearRegression
# Training data
X = [[6], [8], [10], [14], [18]]
y = [[7], [9], [13], [17.5], [18]]
# Create and fit the model
model = LinearRegression()
model.fit(X, y)
print 'A 12" pizza should cost: $%.2f' % model.predict([12])[0]
Und diese Grafik:
Das chard mit meinem Code nicht nach oben übereinstimmt, es doesn‘ t haben die Matplotlib-Chart-Maker-Funktion. Ich habe versucht, Führer zu lesen und meine eigenen machen:
from sklearn.linear_model import LinearRegression
import numpy as np
import matplotlib.pyplot as plt
X = [[6], [8], [10], [14], [18]]
y = [[7], [9], [13], [17.5], [18]]
model = LinearRegression()
model.fit(X, y)
z = np.array([12]).reshape(-1,1)
print ('A 12" pizza should cost: $%.2f' % model.predict(z)[0])
print ("\n" + "_" * 50 + "\n")
plt.figure()
plt.title('Pizza price plotted against diameter')
plt.xlabel('Diameter in inches')
plt.ylabel('Price in dollars')
plt.plot(X, y, z, 'k.')
plt.axis([0, 25, 0, 25])
plt.grid(True)
plt.show()
Aber das gab mir nur dieses seltsames blaues Ding:
Ich bin neu in der Arbeit mit Mathematik in Python, also wenn jemand Könnte mir mehr Informationen geben, wie man das löst, würde es geschätzt.
wie ist das Buch "Mastering Maschinelles Lernen mit Scikit-Learn" ist es für Sie hilfreich? – adhg
So. Viele. Fehler. – Rich
Wirklich? Ich war auf der Suche nach einem Buch in ML mit Scikit; schade – adhg