• Home
  • About me
  • Curriculum
  • Projects
Facebook Linkedin Twitter

MauroCerbai

Software Engineer

EVALUATION METRICS
The most simple and immediate metric is accuracy
accuracy = labeled correctly / all data


but it depends very much on the number of data in input so with different data is not comparable.



To resolve this we use the confusion matrixconfusionMat.png


Each row of the matrix represents the instances in a predicted class while each column represents the instances in an actual class (or vice versa).


Analyzing this data we can extract this two data:





  • recall = how many times you get correctly? (similar to accuracy)
true positive / ( true positive + false negative )


  • precision = once predicted x, what is the probability that is really x?

true positive / ( true positive + false positive )

Share
Tweet
Pin
Share
No commenti
CROSS VALIDATION
One round of cross-validation involves partitioning a sample of data into complementary subsets, performing the analysis on one subset (called the training set), and validating the analysis on the other subset (called the validation set or testing set).
The conventional validation works partitioning the data set into two sets of 70% for training and 30% for test for example.


Sklearn:
from sklearn import cross_validation
feature_train, feature_test, label_train, label_test = cross_validation.train_test_split (iris_data, iris_target, test_size=0.4, random_state=0)


[train]
pca.fit (feature_train)
pca.transform(feature_train)
svc.train(feature_train)


[test]
NO FIT (you want to use the same function as in the training)
pca.transform(feature_test)
svc.train(feature_test)


K-Fold:
K-fold_cross_validation_EN.jpgIn k-fold cross-validation, the original sample is randomly partitioned into k equal sized subsamples. Of the k subsamples, a single subsample is retained as the validation data for testing the model, and the remaining k − 1 subsamples are used as training data.



So, we can explain also like this:
  • repat k times
    • pick 1 block of data as test
    • train against the othe k-1 block
    • test on testing set
  • average final result


Sklearn:
from sklearn.cross_validation import KFold
kf = KFold(len(authors), 2)
for train_indices, test_indices in kf:
feature_train = [word_data[ii] for ii in train_indices]
feature_test = [word_data[ii] for ii in test_indices]
authors_train = [authors[ii] for ii in train_indices]

authors_train = [authors[ii] for ii in test_indices]



GridSearchCV:
Parameter tuning is the process of selecting the values for a model's parameters that maximize the accuracy of the model.
Scikit-learn provides an object that, given data, computes the score during the fit of an estimator on a parameter grid and chooses the parameters to maximize the cross-validation score.
By default, the GridSearchCV's cross validation uses 3-fold KFold or StratifiedKFold depending on the situation.

Sklearn:
parameters = { ‘kernel’: (‘linear’, ‘rbf’), C [1, 10])
svr = svm.SVC
clf = grid_search.GridSearchCV(svr, parameters)
clf.fit(iris_data, iris_target)
print clf.best_params_



Share
Tweet
Pin
Share
No commenti
PRINCIPAL COMPONENT ANALYSISGaussianScatterPCA.jpg


PCA find a new coordinates system that is detained from the old one by translation and rotation only centering the data. The goal is to try making a composite feature that more directly probes the underlying phenomenon ( square footage + number of rooms → size ).


How to determine the pca:
The pca of a dataset is the direction that has the largest variance (variance = spread of data distribution) because it retains the maximum amount of original information. That is true because projecting the original data on the longer axis of the new coordinate system we can have a more spread data value and lose the minimum amount of information possible.projection.png


When to use:
  • access latent feature
  • dimensionality reduction
    • visualize high dimensional data
    • reduce noise
    • use as preprocessing (reducing input for later algo [ eigenfaces] )


Sklearn:
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
pcs.fit(data)
print pca.explained_variance_ratio_
first_pc = pca.components_[0]
second_pc = pca.components_[1]
x_train_pca = pcs.transform(X_test)

Share
Tweet
Pin
Share
No commenti
Every time I open Android Studio this come to mind is this

IMHO


Observer Pattern? MVC? MVP? MVVM? I don't know
Do Androids (Programmer) Dream of Code Order?

Take a look at this post I found useful. Bye
Share
Tweet
Pin
Share
No commenti

I just received this email.
Congratulations!
Dear Mauro,
We are excited to offer you a Google Developer Challenge Scholarship to the Android Developer track.We received applications from many talented and motivated candidates, and yours truly stood out.
I'm very happy to announce that I've been selected for this scholarship involving the famous Google product and the amazing learning platform Udacity. Thank you!
Share
Tweet
Pin
Share
No commenti
OUTLIERS
An outlier is an observation point that is distant from other observations.
OutlierScatterplot_1000.gif


Detention:
You simply follow this flow:
  • Train the algorithm
  • Remove ~10% of data with the largest residual error
  • Train again and evaluate the accuracy test
    • Repeat
The residual of an observed value is the difference between the observed value and the estimated value of the quantity of interest
Share
Tweet
Pin
Share
No commenti
LINEAR REGRESSION220px-Linear_regression.svg.png
In linear regression, the relationships are modeled using linear predictor functions whose unknown model parameters are estimated from the data. Basically a regression output is not discrete but a function like:


y = ax + b
y is target
a is slope
b is intercept


Error metrics:
The error is calculated
error = actual data - predicted data
The best linear regression is the one that
minimizes all points( actual - predicted)2
algo: ordinary least squares (ols) - gradient descent
But it’s not perfect because it’s an high value if you have multiple data point and lower with fewer, so it’s not comparable very well.


Instead R2


R squared measures the fraction of the variance of the dependent variable expressed by the regression. In simple linear regression it is simply the square of the correlation coefficient. It’s independent from the number of data.


(not good) 0 < r2 > 1 (good)

Sklearn:
from sklearn.linear_model import LinearRegression
clf = LinearRegression()
clf.fit(feature_training, label_training)
prediction = clf.predict(feature_test)
accuracy = clf.score(feature_test, label_test) [ -> R2 error metric ]
slope = clf.coef_

intercept = clf.intercept_

Share
Tweet
Pin
Share
No commenti

NAIVE BAYES


Are a family of simple probabilistic classifiers based on applying Bayes’ theorem with strong independent assumptions between the feature.

Theorem:
P(A|B) = P(B|A) P(A) / P(B)

In a hospital the probability of a liver disease is 10%, the probability of the patient being alcoholic is 5% and among those with a liver disease there are a 7% that are alcoholic. What is the probability of a liver disease if the patient is alcoholic?
P(L) = 0,1
P(A) = 0,05
P(A|L) = 0,07
P(L|A) = P(A|L)*P(L) / P(A) = 0.07*0.01 / 0.05 = 0.14 => 14%

It’s a popular method for text categorization with word frequencies as the features but not their order, it assume that the value of a particular feature is independent of the value of any other feature. Basically it count the occurrences of a word in a particular text sample and assign a probability to that, when you need to attribute a particular “email” to someone then it compare the probability of every word of being written by a certain person.

SENDER : CHRIS - Love 0.1 - Deal 0.8 - Life 0.1
SENDER : SARA - Love 0.5 - Deal 0.2 - Life 0.3

P(CHRIS) = 0.5 = P(SARA)
TEXT : Love deal
P(CHRIS) = 0.1*0.8*0.5 = 0.04 -> 0.04/0.09 = 44%
P(SARA) = 0.5*0.2*0.5 = 0.05 -> 0.05/0.09 = 55%

Sklearn:
from sklearn.naive_bayes import GaussianNB
clf = GaussianNB()
clf.fit(feature_training, label_training)
prediction = clf.predict(feature_test)
accuracy = clf.score(feature_test, label_test)


Share
Tweet
Pin
Share
No commenti
For those who, like me, are experimenting with scikit learn
Share
Tweet
Pin
Share
No commenti
Older Posts

About me


Smiley face
Computer Science Degree, technology enthusiast, programmer, interested in startup & innovation, curious, precise & organized.

Follow Me

  • Facebook
  • Linkedin
  • Twitter
  • Bitbucket
  • Github

recent posts

Categories

  • dev
  • development
  • software
  • learn
  • learning
  • machine
  • machine learning
  • study
  • android
  • google
  • job
  • scikit
  • sklearn
  • app
  • udacity
  • gdg
  • google play
  • html
  • code
  • electronics
  • linux
  • script
  • uda
  • webgl
  • database
  • gdgmilano
  • help
  • open source
  • programming
  • smartphone
  • torino
  • weekend
  • work
  • workshop
  • 3d
  • firebase
  • gps
  • greatmind
  • hardware
  • location
  • personal computer
  • start up
  • .bashrc
  • GB
  • PS3
  • Vallée des Merveilles
  • action
  • analytics
  • audio
  • avi
  • bayes
  • books
  • bug
  • cpu
  • dinolib
  • docker
  • fake
  • ffmpeg
  • force
  • francaise
  • france
  • francia
  • free
  • gear 360
  • gglass
  • git
  • gitconfig
  • glass
  • hdd
  • hike
  • hiring
  • jenkins
  • joke
  • kde
  • kmix
  • magnetism
  • material
  • materialdesign
  • merge-it
  • messaging
  • microservices
  • mint
  • naive bayes
  • navigation drawer
  • nemo
  • nikola
  • nikolatesla
  • pc
  • ram
  • reading
  • refuge
  • samsung
  • space
  • spain
  • ssd
  • steam
  • tesla
  • unturned
  • valle delle meraviglie
  • veromix
  • versioning
  • windows
  • wizard
  • wolley
  • wolleybuy
  • xvid

Blog Archive

  • ottobre (1)
  • settembre (1)
  • gennaio (1)
  • novembre (1)
  • maggio (1)
  • aprile (1)
  • marzo (3)
  • febbraio (3)
  • gennaio (1)
  • novembre (7)
  • ottobre (4)
  • settembre (3)
  • agosto (1)
  • luglio (1)
  • settembre (1)
  • agosto (1)
  • giugno (2)
  • aprile (2)
  • marzo (1)
  • febbraio (3)
  • gennaio (2)
  • novembre (1)
  • agosto (2)
  • luglio (2)
  • giugno (3)
  • marzo (1)
  • novembre (1)
  • ottobre (1)
  • agosto (1)
  • giugno (1)
  • maggio (2)
  • marzo (2)
  • febbraio (1)
Facebook Linkedin Twitter Bitbucket Github

Created with by ThemeXpose | Distributed By Gooyaabi Templates