Well, let’s discuss Linear Regression.
There is a scenario where you need to know the price of the pizza. You have all the records of pizza you ate previously like the diameters and prices.
So let’s apply Machine Learning on this.
Training Instance|| Diameter(in) |Price($)
1 6 7
2 8 9
3 10 13
4 14 17.5
5 18 18
now visualize your data graphically :
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()
Now let’s model this relationship using linear regression-
from sklearn.linear_model import LinearRegression
# Training data
X = [[6], [8], [10], [14], [18]]
y = [[7], [9], [13], [17.5], [18]]
# Now Create and fit the model
model = LinearRegression()
model.fit(X, y)
print(A 12" pizza should cost: $%.2f' % model.predict([12])[0])
the output will be something like:
A 12" pizza should cost: $13.68
So this was a very basic, simple ML program.
If you want to become an expert in Machine Learning, checkout this Machine Learning Certification Course offered by Intellipaat.
See this Machine Learning Course for more information :