Create you first ML Model
The feeling of creating our own first Machine learning model is Awesome - like any creation we do for the first time.
Here are a few simple steps to create your own model. I took classification Problem for demonstration.
Problem statement : We have a dataset with salary class {<=50k and >50k} which is our "target" having various features such as age, hours per week, capital gain etc all in Numeric form. (Data set links in Ref.)
Create a Machine Learning Model, Predict the target of first sample, and calculate accuracy of the Model.
## Import pandas and load data. then split data and target
import pandas as pd
adult_census2 = pd.read_csv("../datasets/adult-census-numeric-test.csv")
data2 = adult_census2.drop(columns="class")
target2 = adult_census2["class"]
2. Fit the model with the data
from sklearn.neighbors import KNeighborsClassifier
model2=KNeighborsClassifier(n_neighbors=50)
model2.fit(data2, target2)
3. Predict the target of first sample and compare against the actual data and compare
model2.predict(data[:1])
model2.predict(data[:1])==target2[:1]
4. Compute the accuracy of the created Model "Model2"
accuracy2 = model2.score(data2, target2)
model_name2 = model2.__class__.__name__
print(f"The test accuracy using a {model_name2} is {accuracy2:.3f}")
Thatzz It..!
We have created a Machine learning Model using "scikit-learn" which is a Python Library for Machine Learning task. We used "KNeighborsClassifier" which is one of the classifier algorithm we used to demonstrate.
Kindly note the solution is over simplified for novice learning purpose, though there are many good algorithms with various datasets
Ref Data Set:
Courtesy to -
INRIA - MOOC - Scikit Learning Experience - https://www.inria.fr/en/mooc-scikit-learn
CISO - South Asia and India | Information Security Management
1 年Great work Shankar, agree always exciting when we do it for the first time