Posts

Simple Linear Regression

The Simple Linear Regression model import pandas as pd import pylab as pl import matplotlib.pyplot as plt import numpy as np %matplotlib inline #url https://s3-api.us-geo.objectstorage.softlayer.net/cf-courses-data/CognitiveClass/ML0101ENv3/labs/FuelConsumptionCo2.csv #### Load Data #### df = pd.read_csv("FuelConsumption.csv") cdf = df[['ENGINESIZE','CYLINDERS','FUELCONSUMPTION_COMB','CO2EMISSIONS']] # Taking Engine Size as independent Value i.e., X and Dependent value as Co2 Emission i.e., y X = cdf[['ENGINESIZE']] y = cdf[['CO2EMISSIONS']] #### split dataset into train and test #### ''' Next, we have to split the dataset into training and testing. We will use the training dataset for training the model and then check the performance of the model on the test dataset. For this, we will use the train_test_split method from the library model_selection We are providing a test_size of 1/3 whic...

Multiple Linear Regression

Creating a Multiple linear regression model for estimating CO2 emission from a car model using independent variables like Engine size, cylinder, fuel consumption of a car. import matplotlib.pyplot as plt import pandas as pd import pylab as pl import numpy as np %matplotlib inline df = pd.read_csv("FuelConsumptionCo2.csv") #df.head() cdf = df[['ENGINESIZE','CYLINDERS','FUELCONSUMPTION_COMB','CO2EMISSIONS']] #cdf.head(9) # Plotting plt.scatter(cdf.ENGINESIZE, cdf.CO2EMISSIONS, color = 'blue') plt.xlabel('Engine Size') plt.ylabel('Emissions') #plt.show() # Creating train and test dataset msk = np.random.rand(len(df)) < 0.8 train = cdf[msk] test = cdf[~msk] # train data distribution plt.scatter(train.ENGINESIZE, train.CO2EMISSIONS, color='blue') plt.xlabel("Engine size") plt.ylabel("Emission") #plt.show() #### MULTIPLE REGRESSION MODEL #### from sklea...

IRIS ML Project

Using the IRIS dataset to estimate the class of the IRIS using different ML Algorithms. import pandas from pandas . plotting import scatter_matrix import matplotlib . pyplot as plt from sklearn import model_selection from sklearn . metrics import classification_report from sklearn . metrics import confusion_matrix from sklearn . metrics import accuracy_score from sklearn . linear_model import LogisticRegression from sklearn . tree import DecisionTreeClassifier from sklearn . neighbors import KNeighborsClassifier from sklearn . discriminant_analysis import LinearDiscriminantAnalysis from sklearn . naive_bayes import GaussianNB from sklearn . svm import SVC url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' names = [ 'sepal length' , 'sepal width' , 'petal length' , 'petal width' , 'class' ] dataset = pandas . read_csv ( url , names = names ) print...