Initializing Core...
Initializing Core...
Operational
Let's build our first Machine Learning model!
We'll predict student marks based on how many hours they studied. 🎯
We’ll use:
Jupyter lab or Google Colab for codingpandas to handle datanumpy for mathmatplotlib to plotscikit-learn to build the modelimport pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom sklearn.linear_model import LinearRegression
data = {"Hours": [1, 2, 3, 4, 5, 6, 7],"Marks": [10, 20, 30, 40, 50, 60, 70]}df = pd.DataFrame(data)print(df)
plt.scatter(df["Hours"], df["Marks"])plt.title("Study Hours vs Marks")plt.xlabel("Hours")plt.ylabel("Marks")plt.show()
X = df[["Hours"]] # Featuresy = df["Marks"] # Targetmodel = LinearRegression()model.fit(X, y)
predicted = model.predict([[5]])print(f"Predicted Marks for 5 hours of study: {predicted[0]:.2f}")
plt.scatter(X, y)plt.plot(X, model.predict(X), color='red') # Best fit lineplt.title("Study Hours vs Marks (Model)")plt.xlabel("Hours")plt.ylabel("Marks")plt.show()
pandas, numpy, matplotlib, and scikit-learn.