Python

predict and evaluate multivariate linear regression model

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 15 11:37:53 2019
https://www.ritchieng.com/machine-learning-evaluate-linear-regression-mo...
@author: K
"""

# imports
import pandas as pd
import seaborn as sns
import statsmodels.formula.api as smf
from sklearn.linear_model import LinearRegression
from sklearn import metrics
from sklearn.cross_validation import train_test_split
import numpy as np

# allow plots to appear directly in the notebook
#%matplotlib inline

sklearn linear_model LinearRegression on Salaries

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import statsmodels.api as sm
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import r2_score
import warnings
#from IPython import get_ipython
#ipy = get_ipython()
#if ipy is not None:
#    ipy.run_line_magic('matplotlib', 'inline')
sns.set()
#%matplotlib inline

df = pd.read_csv("./SalaryData1.csv")
print(df.shape)
print(df.isnull().values.any())

Naive Bayes Classifier for Multinomial Models

# -*- coding: utf-8 -*-
"""
Naive Bayes Classifier for Multinomial Models
@author: K
"""

import logging
import pandas as pd
import numpy as np
from numpy import random
#import gensim
import nltk
from sklearn.model_selection import train_test_split
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer
from sklearn.metrics import accuracy_score, confusion_matrix
import matplotlib.pyplot as plt
from nltk.corpus import stopwords
import re
from bs4 import BeautifulSoup
from IPython import get_ipython

Regression lineaire avec des listes en entrées

# -*- coding: utf-8 -*-
"""
Regression lineaire avec des listes en entrées
"""

import matplotlib.pyplot as plt
import numpy as np
import statsmodels.api as sm


#Farm size in hectares
X=[1,1,2,2,2.3,3,3,3.5,4,4.3]
#Crop yield in tons
Y=[6.9,6.7,13.8,14.7,16.5,18.7,17.4,22,29.4,34.5]
"""
#    By default, OLS implementation of statsmodels does not include an intercept 
#     in the model unless we are using formulas.
#    We need to explicitly specify the use of intercept in OLS method by 
#     adding a constant term.
X_1 = sm.add_constant(X)
#print(X_1)

sklearn neural_net & export to js !

# -*- coding: utf-8 -*-
"""
Created on Mon Jan 21 01:30:05 2019

@author: K
"""

from sklearn.preprocessing import StandardScaler
from sklearn.datasets import load_breast_cancer
cancer = load_breast_cancer()
print(cancer['data'].shape)
X = cancer['data']
y = cancer['target']

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y)

#from sklearn.preprocessing import StandardScaler
from sklearn import preprocessing
#scaler = StandardScaler()
# Fit only to the training data
X_train = preprocessing.scale(X_train)

Réseau neuronal à 1 couche cachée


# -*- coding: utf-8 -*-
"""
Created on Thu Dec 13 14:50:40 2018

@author: K
"""

import numpy as np
import time
import scipy.io
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split

datas = scipy.io.loadmat('ex4data1.mat')
X = datas["X"]
y =  datas["y"]
im = X[2098].reshape(20, 20);
plt.imshow(im, cmap='gray')
#plt.imshow(X[0]).reshape([20, 20]);


#print(type(X[0]))
#realout = 
Y = np.zeros((5000,1))
for i in range(0, 5000):
    for j in range(1, 10):
        if np.mod(y[i],2) == 0:
            Y[i,0] = 1
        else:

Time Series forecasting

# -*- coding: utf-8 -*-
"""
Created on Tue Jan 22 11:17:01 2019
https://www.analyticsvidhya.com/blog/2016/02/time-series-forecasting-cod...
@author: K
"""

from statsmodels.tsa.stattools import adfuller
import pandas as pd
import numpy as np
import matplotlib.pylab as plt

from matplotlib.pylab import rcParams
rcParams['figure.figsize'] = 15, 6

dateparse = lambda dates: pd.datetime.strptime(dates, '%Y-%m')

Tags:

Pages

Subscribe to Python