Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.ensemble import GradientBoostingRegressor | |
# Instantiate gradient boosting | |
grbst = GradientBoostingRegressor(max_depth=5, | |
n_estimators=300, | |
random_state=5) | |
# Fit gb to the training set | |
grbst.fit(X_train,y_train) | |
# Predict test set labels |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
#In questa sezione Le librerie necessarie per visualizzare in via interattiva | |
#la nostra spezzata | |
from bokeh.layouts import column | |
from bokeh.models import ColumnDataSource, Plot, Select,LinearAxis, Grid, HoverTool | |
from bokeh.plotting import figure,curdoc | |
from bokeh.io import show,push_notebook, output_notebook,output_file |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from sklearn.model_selection import train_test_split | |
#Importiamo i classificatori che vogliamo allenare | |
from sklearn.naive_bayes import MultinomialNB | |
from sklearn.linear_model import LogisticRegression |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Qui lavoro di har code per semplicita dei tre file | |
#Nel futuro riutilizzerò del codice per la lettura automatica dei tre file | |
file_1='datatraining.txt' | |
file_2='datatest.txt' | |
file_3='datatest2.txt' | |
df_train=pd.read_csv(file_1) | |
df_train.name="Training DataSet" | |
df_test=pd.read_csv(file_2) | |
df_test.name="Test DataSet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Convertiamo in timestamp la colonna 'Date' per una migliore manipolazione, nel caso fosse necessaria | |
datetime=pd.to_datetime(df_train.date) | |
df_train['date']=datetime | |
print(df_train.info()) | |
#Essendo 8 variabili e tra loro potenzialmente correlate | |
#Creiamo un subplot lungo la medesima verticale | |
fig, ax= plt.subplots(df_train.shape[1]-1,sharex=True,figsize=(20,30)) | |
for i in range(df_train.shape[1]-1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#In questa sezione importiamo i moduli per la visualizzazione interattiva dei dati | |
from bokeh.layouts import column | |
from bokeh.models import ColumnDataSource, Plot, Select,LinearAxis, Grid, HoverTool | |
from bokeh.models.glyphs import VBar | |
from bokeh.plotting import figure,curdoc | |
from bokeh.io import show,push_notebook, output_notebook,output_file | |
#Output_notebook() è necessario per visualizzare | |
#i grafici all'interno di jupyter notebook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Una analisi della correlazione non sarebbe male | |
#Si potrebbe creare un plot che permette di selezionare le variabili | |
#e in funzione di questa ti plotta la correlazione | |
#oltre che a una heat map | |
#Adesso possiamo passare alla parte di Machine Learning | |
#In primis andiamo a definire due funzioni | |
#La funzione get_prediction | |
#Che effettuerà il training sulla base del | |
#classificatore scelto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pandas as pd | |
import random | |
#Il random seed ci permette di generare del codice pseudocasuale | |
random.seed(30) | |
#Ho generato 1000 campioni di altezze | |
#Attraverso una distribuzione Uniforme ed una Normale | |
random_height_un=np.random.uniform(1.50, 2.00, 1000).round(2) | |
#In italia l'altezza media è di 1.77, sono 7 cm sotto il valore medio |
OlderNewer