%matplotlib inline
import numpy as np
from sklearn.datasets import load_iris
import pandas as pd
import matplotlib.pyplot as plt
iris_data = load_iris()
iris = pd.DataFrame(iris_data.data, columns=iris_data.feature_names)
iris['species'] = iris_data.target
print(iris_data.target_names)
iris.head()
x = iris.iloc[:,0]
y = iris.iloc[:,2]
plt.xlabel("sepal length (cm)")
plt.ylabel("petal length (cm)")
plt.scatter(x, y, c=iris['species'])
plt.show()
from sklearn.linear_model import LinearRegression
x = iris.loc[iris['species']==2].iloc[:,0].values.reshape(-1, 1)
y = iris.loc[iris['species']==2].iloc[:,2]
model = LinearRegression()
model.fit(x, y)
print("Predicted petal length for 6.5cm sepal length:", model.predict(6.5))
# Plot
x_new = np.linspace(4.5, 8.0, 100).reshape(-1, 1)
y_new = model.predict(x_new)
plt.scatter(x, y)
plt.plot(x_new, y_new)
plt.show()