Friday 22 May 2020

Linear Regression in python | python crash course_06

Linear Regression in Machine learning :

Welcome to machine learning in python crash course, so in this section we will learn different machine learning algorithm. Let's start:
Linear Regressions is usually the first machine learning algorithm. It is a simple model but everyone need to master it as it lays the foundation for other machine learning algorithm.

Where can Linear Regressions be used?

It is a very powerful techniques and can be used to understand the factors that influence profitability. It can be used to forecast sale in the coming months by analyzing the sales data for previous month. It can also be used to gain various insights into customers behaviour. By the end of the blog, we will build a model which looks like the below picture i.e, determine a line which best fit the data.
Example
In this example, we will use Pima Indian Diabetes dataset to select four of the attributes having best features with the help of chi-square statistical test.
from pandas import read_csv
from numpy import set_printoptions
from sklearn.feature_selection import SelectKBest
from sklearn.feature_selection import chi2
path = r'C:\pima-indians-diabetes.csv'
names = ['preg', 'plas', 'pres', 'skin', 'test', 'mass', 'age', 'class']
dataframe = read_csv(path, names=names)
array = dataframe.value

Next, we will separate array into inputs and outputs components −
X = array[:,0:8]

Y = array[:,8]
The following line of code will select the best features from dataset −
test = SelectKBest(score_func=chi2, k=4)

fit = test.fit(X,Y)
set_printoptions(precision=2)
print(fit.scores_)
featured_data = fit.transform(X)
print ("\nFeatured data:\n", featured_data[0:4])

OUTPUT:
[ 111.52 1411.89 17.61 53.11 2175.57 127.67 5.39 181.3 
Featured data:
[[148.  0. 33.6 50. 
[  89. 94. 28.1 21. ]]
[  85.  0. 26.6 31. ]
[ 183.  0. 23.3 32. ]
(Note: for python top 15 interview question click here)

                                     BEST OF LUCK!!!!!
Telegram: https://t.me/clcoding_python
https://www.facebook.com/pirawenpython/ https://www.facebook.com/groups/pirawenpython/


0 Comments:

Post a Comment

Popular Posts

Categories

AI (27) Android (24) AngularJS (1) Assembly Language (2) aws (17) Azure (7) BI (10) book (4) Books (112) C (77) C# (12) C++ (82) Course (60) Coursera (176) coursewra (1) Cybersecurity (22) data management (11) Data Science (85) Data Strucures (6) Deep Learning (9) Django (6) Downloads (3) edx (2) Engineering (14) Excel (13) Factorial (1) Finance (5) flutter (1) FPL (17) Google (18) Hadoop (3) HTML&CSS (46) IBM (25) IoT (1) IS (25) Java (92) Leet Code (4) Machine Learning (43) Meta (18) MICHIGAN (4) microsoft (3) Pandas (3) PHP (20) Projects (29) Python (719) Python Coding Challenge (154) Questions (2) R (70) React (6) Scripting (1) security (3) Selenium Webdriver (2) Software (17) SQL (40) UX Research (1) web application (8)

Followers

Person climbing a staircase. Learn Data Science from Scratch: online program with 21 courses