Sunday, June 27, 2021

Car price prediction using Machine learning python



This blog contains the source code for Machine learning project car price prediction using python.


Step 1: Installing libraries

*pip install numpy
*pip install pandas
*pip install sklearn


Step 2: Importing the libraries

import pandas as pd
import numpy as np
from sklearn import linear_model


Step 3: Reading the CSV

df=pd.read_csv('car_data.csv')
df


Step 4: Preprocessing 1:

inputs=df.drop(['Car_Name','Owner','Seller_Type'],axis='columns') 
target=df.Selling_Price
inputs


Step 5: Preprocessing 2

from sklearn.preprocessing import LabelEncoder
Numerics=LabelEncoder()

inputs['Fuel_Type_n']=Numerics.fit_transform(inputs['Fuel_Type'])
inputs['Transmission_n']=Numerics.fit_transform(inputs['Transmission'])
inputs


Step 6: Dropping the string columns

inputs_n=inputs.drop(['Fuel_Type','Transmission','Selling_Price'],axis='columns') 
inputs_n


Step 7: Implemention of Linear regression & Prediction

model=linear_model.LinearRegression()
model.fit(inputs_n,target)
pred=model.predict([[2013,9.54,430000,1,1]])


Fullcode: Github




Thanks for reading this blog..!

 

Tuesday, June 22, 2021

OCR using Pytesseract library in python ( 20 lines )



This blog contains code for the text detection using open-cv and Pytesseract
 libraries in python


STEP1: Installation of libraries 

*pip install OpenCV-python

*pip install pillow

*pip install Pytesseract


STEP2: Import the libraries 

import cv2
from PIL import Image
from pytesseract import pytesseract


STEP3: Accessing webcam

camera=cv2.VideoCapture(0)


STEP4: The Loop

while True:
    _,image=camera.read()
    cv2.imshow('image',image)
    if cv2.waitKey(1)& 0xFF==ord('s'):
        cv2.imwrite('test1.jpg',image)
        break
camera.release()
cv2.destroyAllWindows()


STEP5: Converting Text to speech

def tesseract():
    path_to_tesseract = r"C:\Program Files\Tesseract-OCR\tesseract.exe"
    image_path = "test1.jpg"
    pytesseract.tesseract_cmd = path_to_tesseract
    text = pytesseract.image_to_string(Image.open(image_path))
    print(text[:-1])
tesseract()

Full code :GIthub




Thanks for reading this blog..!

Saturday, June 19, 2021

Salary prediction using python

This blog contains the code for salary prediction machine learning project using python.





STEP1:Installing requirements:

*pip install numpy

*pip install pandas

*pip install sklearn


STEP2:Importing modules

import numpy as np

import pandas as pd


STEP3:Reading CSV

data=pd.read_csv('Salary_Data.csv') # Dataset in Github
data


STEP4:Reshaping

x=data.YearsExperience.values.reshape(-1,1)
y=data.Salary.values.reshape(-1,1)

STEP5:Spliting the dataset

from sklearn.model_selection import train_test_split
xtrain,xtest,ytrain,ytest=train_test_split(x,y,test_size=0.3,random_state=0)


STEP6: LinearRegression formula

from sklearn.linear_model import LinearRegression
model=LinearRegression()

STEP7: Applying the formula & prediction

model.fit(x,y)
next_salary=model.predict([[6]])
print(int(next_salary))

STEP8: Accuray

model.score(xtrain,ytrain)


Full code:Github


Thanks for reading the article❤



Sunday, June 13, 2021

Weather prediction using python Machine learning project ( NaΓ―ve Bayes )

 This blog contains the code for Weather prediction machine learning project using python Programming




STEP1: Installing Dependencies

*pip install pandas
*pip install sklearn

STEP2: Importing the libraries

#NaiveBayes project (Weather Prediction)
#Required Modules
import pandas as pd
from sklearn.preprocessing import LabelEncoder
from sklearn.naive_bayes import GaussianNB

STEP3:Reading the CSV

df = pd.read_csv("new_dataset.csv")
df

STEP4:Encoding the strings into numbers:

Numerics=LabelEncoder()


STEP5:Dropping the target column

inputs=df.drop('Play',axis='columns')
target=df['Play']
target

STEP6:Creating new dataframe

inputs['outlook_n']= outlook_at.fit_transform(inputs['Outlook'])
inputs['Temp_n']= outlook_at.fit_transform(inputs['Temp'])
inputs['Hum_n']= outlook_at.fit_transform(inputs['Humidity'])
inputs['win_n']= outlook_at.fit_transform(inputs['Windy'])
inputs


STEP7: Dropping the string columns

inputs_n=inputs.drop(['Outlook','Temp','Humidity','Windy'],axis='columns')
inputs_n

STEP8: Applying GaussianNB

classifier = GaussianNB()
classifier.fit(inputs_n,target)

STEP9: Prediction

classifier.predict([[0,0,0,1]])


Video explanation:




                                                               

Fullcode:Github


Thanks for reading the article❤




Wednesday, June 9, 2021

Voice Translator using python ( 25 lines )

Hello python programmers, This blog contains the code for voice translator using python








STEP 1: Libraries required

*pip install speech Recognition
*pip install google_trans_new
*pip install pyttsx3

STEP 2:Importing the libraries

import speech_recognition as sr
from google_trans_new import google_translator
import pyttsx3

STEP3: Creating Instances 

recognizer=sr.Recognizer()
engine=pyttsx3.init()

STEP4:Recording the audio

with sr.Microphone() as source:
    print('Clearing the background noises..')
    recognizer.adjust_for_ambient_noise(source,duration=1)
    print('Waiting for your message')
    audio=recognizer.listen(source,timeout=1)
    print('Done recording')
try:
    print('Recognizing')
    result=recognizer.recognize_google(audio,language='en')
except Exception as ex:
    print(ex)

STEP5: Translation

def trans():
    langinput=input('Type the language code you want to translate:')
    translator=google_translator()
    translate_text=translator.translate(str(result),lang_tgt=str(langinput))
    print(translate_text)
    engine.say(str(translate_text))
    engine.runAndWait()
trans()


Fullcode: Github







Saturday, June 5, 2021

Instagram Automation ( send messages ) using python

 Hello python programmers, In this video we're going to see about how to create a Instagram Bot using python

With the help of selenium we're going to create this one.



STEP1: Libraries Installation:

*pip install selenium 

STEP2: Importing the Libraries:

from selenium import webdriver
import time
browser = webdriver.Chrome('chromedriver.exe')
browser.get('https://instagram.com/')
time.sleep(4) 

STEP3: Login autoamation:

def login()
    Username=browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input")
    Username.send_keys("username")
    time.sleep(4)
    password=browser.find_element_by_xpath("/html/body/div[1]/section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input")
    password.send_keys("password")
    password.submit()
    time.sleep(7)

STEP4:Blocking the Notifications

def notification():
    Notnow=browser.find_element_by_xpath('/html/body/div[1]/section/main/div/div/div/div/button').click()
    time.sleep(3)
    noti=browser.find_element_by_xpath('/html/body/div[4]/div/div/div/div[3]/button[2]').click()
    time.sleep(7)

STEP5:Message icon:

def message():
    msgclick=browser.find_element_by_class_name('xWeGp')
    msgclick.click()
    time.sleep(6)

STEP6: Final part:

def final():
    chaticon=browser.find_element_by_class_name('QBdPU').click()
    time.sleep(7)
    typename=browser.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/div[1]/div/div[2]/input')
    typename.send_keys('username who you want to send.!')
    time.sleep(7)
    name=browser.find_element_by_xpath('/html/body/div[5]/div/div/div[2]/div[2]/div[2]/div/div[2]/div[2]/div').click()
    time.sleep(7)
    next=browser.find_element_by_class_name('rIacr').click()
    time.sleep(7)
    mbox=browser.find_element_by_tag_name('textarea')
    mbox.send_keys('Hi')
    send=browser.find_element_by_xpath('/html/body/div[1]/section/div/div[2]/div/div/div[2]/div[2]/div/div[2]/div/div/div[3]/button')
    send.click()


Thanks for reading this article..!

Fullcode: Github








Wednesday, June 2, 2021

K means clustering project using python

Hello python programmers, This is AK. In this video we’re going to see about one of the most popular and important algorithms in machine learning that is named as kmeans clustering.



STEP1: Installing Dependencies

* pip install pandas
* pip install matplotlib
* pip install scikit-learn

STEP2: Importing the libraries

from pandas import pandas as pd
from pandas import DataFrame
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans

STEP3: Read the CSV

data=pd.read_csv('Sample scores.csv') data

Dataset link: http://bitly.ws/dIvR

STEP4: Plot the data

plt.scatter(data['Overs'],data['Scores'])
plt.xlabel('x')
plt.ylabel('y')
plt.show()


STEP5: Create dataframe

df=DataFrame(data,columns=['Scores','Overs']) df


STEP6: Create Clusters

kmeans=KMeans(n_clusters=3).fit(df)


STEP7: Place the centroid points

centroids=kmeans.cluster_centers_ print(centroids)


STEP8: Plot the data points

plt.scatter(df['Overs'],df['Scores'],c=kmeans.labels_.astype(float),s=50,alpha=1) plt.scatter(centroids[:,0],centroids[:,1],c='red',s=50) plt.xlabel('Overs') plt.ylabel('Scores') plt.show()


Github repository : https://github.com/akpythonyt/ML-algorithms



Thanks for reading this article..!