Machine Learning Code

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)

Pages

Subscribe to Machine Learning Code