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.

  1. Import pandas and load dataset. Then split "data" and "target".

## 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:

https://inria.github.io/scikit-learn-mooc/python_scripts/02_numerical_pipeline_ex_00.html

Courtesy to -

INRIA - MOOC - Scikit Learning Experience - https://www.inria.fr/en/mooc-scikit-learn

Giridhar Rangavajalla

CISO - South Asia and India | Information Security Management

1 年

Great work Shankar, agree always exciting when we do it for the first time

要查看或添加评论,请登录

Shankar Murali的更多文章

  • Slow or Fast - Its a Choice

    Slow or Fast - Its a Choice

    Life is a series of choices, each leading to the next, shaping the path we take. I wasn't always a book lover.

  • The Personal Mastery Framework

    The Personal Mastery Framework

    (A framework for Healthy, Happy and Contented Life) Below is my Novel work, simplified for general Audience. During my…

    1 条评论
  • Vande Mukunda Hare..!

    Vande Mukunda Hare..!

    It is Krishna's Birthday, he is now 97 yrs old. He woke up at 5 am and did Yoga, Pooja and other rituals which he was…

  • Financial Preparedness Program with Mermaid Visualisation

    Financial Preparedness Program with Mermaid Visualisation

    Was trying to create a financial preparedness program with mermaid visuals using Python. After few iteration am able to…

  • What exactly is Services and Programs in Windows?

    What exactly is Services and Programs in Windows?

    This is a common question in minds of any Security Practitioners. This article will throw some light on execution of…

  • Ordinary Man with Extra Ordinary Mind

    Ordinary Man with Extra Ordinary Mind

    Once upon a time, i was walking to my new office in Bangalore. Suddenly a stranger came and ask me “where is the…

  • The Short Fable about Economy and Business

    The Short Fable about Economy and Business

    Long before Government of Richland Printed new 100 r notes and distributed to economy (citizens). We will take a sample…

    1 条评论
  • The Story of Bob and Sally - The Power of Data

    The Story of Bob and Sally - The Power of Data

    A Fictional Story Sally is working in a Search Engine company. She was assigned to experiment "behavior changing"…

  • Python Basics

    Python Basics

    Credit - MIT Open Courseware - https://ocw.mit.

  • Uniting Threat Vulnerability and Risk

    Uniting Threat Vulnerability and Risk

    I have an unclear vision for a long time on “how i can combine Risk, Vulnerability and Threat data available and use it…

社区洞察

其他会员也浏览了