# AI News, Advice for applying Machine Learning¶

- On Sunday, August 5, 2018
- By Read More

## Advice for applying Machine Learning¶

train_sizes=np.linspace(.1, 1.0, 5)):

Training vector, where n_samples is the number of samples and

If an integer is passed, it is the number of folds (defaults to 3).

sklearn.cross_validation module for the list of possible objects

estimator, X, y, cv=5, n_jobs=1, train_sizes=train_sizes)

train_scores_mean + train_scores_std, alpha=0.1,

color="r")

test_scores_mean + test_scores_std, alpha=0.1, color="g")

label="Training score")

label="Cross-validation score")

n_redundant=2, n_classes=2, random_state=0) from

columns = range(20) + ["class"]) Notice

This simple cheat-sheet (credit goes to Andreas Müller and the sklearn-team) can help to select an appropriate ML method for your problem (see http://dlib.net/ml_guide.svg for an alternative cheat sheet). In[8]:

width=800, height=600) Out[8]:Since we have 1000 samples, are predicting a category, and have labels, the sheet recommends that we use a LinearSVC (which stands for support vector classification with linear kernel and uses an efficient algorithm for solving this particular problem) first.

X, y, ylim=(0.8, 1.01),

train_sizes=np.linspace(.05, 0.2, 5)) We

X, y, ylim=(0.8, 1.1),

train_sizes=np.linspace(.1, 1.0, 5)) We

There are different ways of obtaining more data, for instance we (a) might invest the effort of collecting more, (b) create some artificially based on the existing ones (for images, e.g., rotation, translation, distortion), or (c) add artificial noise. If

X[:, [11, 14]], y, ylim=(0.8, 1.0),

train_sizes=np.linspace(.05, 0.2, 5)) Note

("svc", LinearSVC(C=10.0))]),

"SelectKBest(f_classif, k=2) + LinearSVC(C=10.0)",

X, y, ylim=(0.8, 1.0),

train_sizes=np.linspace(.05, 0.2, 5)) This

Others would be: (a) reduce the degree of a polynomial model in linear regression, (b) reduce the number of nodes/layers of an artificial neural network, (c) increase bandwidth of an RBF-kernel etc. One

X, y, ylim=(0.8, 1.0),

train_sizes=np.linspace(.05, 0.2, 5)) This

param_grid={"C": [0.001, 0.01, 0.1, 1.0, 10.0]}) plot_learning_curve(est,

X, y, ylim=(0.8, 1.0),

train_sizes=np.linspace(.05, 0.2, 5)) print

"LinearSVC(C=0.1, penalty='l1')",

X, y, ylim=(0.8, 1.0),

train_sizes=np.linspace(.05, 0.2, 5)) This

0.004135 0.

X, y, ylim=(0.5, 1.0),

train_sizes=np.linspace(.1, 1.0, 5)) Wow,

columns = range(2) + ["class"]) _

X_extra, y, ylim=(0.5, 1.0),

train_sizes=np.linspace(.1, 1.0, 5)) Perfectly!

"SVC(C=2.5, kernel='rbf', gamma=1.0)",

X, y, ylim=(0.5, 1.0),

train_sizes=np.linspace(.1, 1.0, 5)) Yes,

This classifier learns a linear model (just as LinearSVC or logistic regression) but uses stochastic gradient descent for training (just as artificial neural networks with backpropagation do typically).

Note that SGDClassifier is sensitive to feature scaling and thus a common preprocessing on real datasets is to standardize the data with, e.g., StandardScaler such that every feature has mean 0 and variance 1. SGDClassifier

instead progressive validation is used: here, the estimator is tested always on the next chunk of training data (before seeing it for training).

n_redundant=0, n_classes=10, class_sep=2,

random_state=0) In[23]:

plot tells us that after 50 mini-batches of data we are no longer improving on the validation data and could thus also stop training.

iy = 10 * j + 1

img[ix:ix + 8, iy:iy + 8] = X[i * n_img_per_row + j].reshape((8, 8)) plt.imshow(img,

have thus 1083 examples of hand-written digits (0, 1, 2, 3, 4, 5), where each of those consists of an $8 \times 8$ gray-scale image of 4-bit pixels (0, 16).

color=plt.cm.Set1(y[i] / 10.),

fontdict={'weight': 'bold', 'size': 12})

# only print thumbnails with matplotlib >

shown_images = np.array([[1., 1.]]) # just something big

dist = np.sum((X[i] - shown_images) ** 2, 1)

if np.min(dist) <

# don't show points that are too close

continue

shown_images = np.r_[shown_images, [X[i]]]

imagebox = offsetbox.AnnotationBbox(

offsetbox.OffsetImage(digits.images[i], cmap=plt.cm.gray_r),

X[i])

ax.add_artist(imagebox)

"Principal Components projection of the digits (time: %.3fs)"

"t-SNE embedding of the digits (time: %.3fs)"

hinge loss (used in support-vector classification) results in solutions which are sparse in the data (due to it being zero for $f(x) > 1$) and is relatively robust to outliers (it grows only linearly for $f(x)\to-\infty$) .

The perceptron loss, on the other hand, is happy as long as a datapoint is on the correct side of the boundary, which leaves the boundary under-determined if the data is truly linearly separable and results in worse generalization than a maximum-margin boundary. Summary¶ We

A first impression of a moderately complex signal processing pipeline can be obtained from a pySPACE example for detecting a specific event-related potential in EEG data: https://github.com/pyspace/pyspace/blob/master/docs/examples/specs/node_chains/ref_P300_flow.yaml This

signal processing pipeline contains nodes for data standardization, decimation, band-pass filtering, dimensionality reduction (xDAWN is a supervised method for this), feature extraction (Local_Straightline_Features), and feature normalization.

Image(filename='algorithm_types_detailed.png', width=800, height=600) Out[30]:One of the long-term goals of machine learning, which is pursued among others in the field of deep learning, is to allow to learn large parts of such pipelines rather than to hand-engineer them. In[31]:

- On Sunday, August 5, 2018
- By Read More

## Feature scaling

Feature scaling is a method used to standardize the range of independent variables or features of data.

In data processing, it is also known as data normalization and is generally performed during the data preprocessing step.

Since the range of values of raw data varies widely, in some machine learning algorithms, objective functions will not work properly without normalization.

For example, the majority of classifiers calculate the distance between two points by the Euclidean distance.

If one of the features has a broad range of values, the distance will be governed by this particular feature.

Therefore, the range of all features should be normalized so that each feature contributes approximately proportionately to the final distance.

Another reason why feature scaling is applied is that gradient descent converges much faster with feature scaling than without it.[1]

Also known as min-max scaling or min-max normalisation, is the simplest method and consists in rescaling the range of features to scale the range in [0, 1] or [−1, 1].

Selecting the target range depends on the nature of the data.

The general formula is given as:

x

′

=

{\displaystyle x'={\frac {x-{\text{min}}(x)}{{\text{max}}(x)-{\text{min}}(x)}}}

{\displaystyle x}

is an original value,

{\displaystyle x'}

is the normalized value.

For example, suppose that we have the students' weight data, and the students' weights span [160 pounds, 200 pounds].

To rescale this data, we first subtract 160 from each student's weight and divide the result by 40 (the difference between the maximum and minimum weights).

{\displaystyle x'={\frac {x-{\text{average}}(x)}{{\text{max}}(x)-{\text{min}}(x)}}}

{\displaystyle x}

is an original value,

{\displaystyle x'}

is the normalized value.

In machine learning, we can handle various types of data, e.g.

audio signals and pixel values for image data, and this data can include multiple dimensions.

Feature standardization makes the values of each feature in the data have zero-mean (when subtracting the mean in the numerator) and unit-variance.

This method is widely used for normalization in many machine learning algorithms (e.g., support vector machines, logistic regression, and artificial neural networks)[2][citation needed].

The general method of calculation is to determine the distribution mean and standard deviation for each feature.

Next we subtract the mean from each feature.

Then we divide the values (mean is already subtracted) of each feature by its standard deviation.

{\displaystyle x'={\frac {x-{\bar {x}}}{\sigma }}}

{\displaystyle x}

is the original feature vector,

{\displaystyle {\bar {x}}}

is the mean of that feature vector, and

{\displaystyle \sigma }

is its standard deviation.

Another option that is widely used in machine-learning is to scale the components of a feature vector such that the complete vector has length one.

This usually means dividing each component by the Euclidean length of the vector:

In some applications (e.g.

Histogram features) it can be more practical to use the L1 norm (i.e.

Manhattan Distance, City-Block Length or Taxicab Geometry) of the feature vector.

This is especially important if in the following learning steps the Scalar Metric is used as a distance measure.

In stochastic gradient descent, feature scaling can sometimes improve the convergence speed of the algorithm[2][citation needed].

In support vector machines,[3]

it can reduce the time to find support vectors.

Note that feature scaling changes the SVM result[citation needed].

- On Sunday, August 5, 2018
- By Read More

Box 5046, 2600 GA Delft The Netherlands email: duin '@' ph.tn.tudelft.nl http : //www.ph.tn.tudelft.nl/~duin tel +31 15 2786143 Data Set Information: This dataset consists of features of handwritten numerals (`0'--`9') extracted from a collection of Dutch utility maps.

200 patterns per class (for a total of 2,000 patterns) have been digitized in binary images.

These digits are represented in terms of the following six feature sets (files): 1.

mfeat-pix: 240 pixel averages in 2 x 3 windows;

In each file the 2000 patterns are stored in ASCI on 2000 lines.

The first 200 patterns are of class `0', followed by sets of 200 patterns for each of the classes `1' - `9'.

Using the pixel-dataset (mfeat-pix) sampled versions of the original images may be obtained (15 x 16 pixels).

- On Sunday, August 5, 2018
- By Read More

## Open Machine Learning Course. Topic 6. Feature Engineering and Feature Selection

In this course, we have already seen several key machine learning algorithms.

Any experienced professional can recall numerous times when a simple model trained on high-quality data was proven to be better than a complicated multi-model ensemble built on data that wasn’t clean.

To start, I wanted to review three similar but different tasks: This article will contain almost no math, but there will be a fair amount of code.

There are ready-to-use tokenizers that take into account peculiarities of the language, but they make mistakes as well, especially when you work with specific sources of text (newspapers, slang, misspellings, typos).

The easiest approach is called Bag of Words: we create a vector with the length of the dictionary, compute the number of occurrences of each word in the text, and place that number of occurrences in the appropriate position in the vector.

In practice, you need to consider stop words, the maximum length of the dictionary, more efficient data structures (usually text data is converted to a sparse vector), etc.

This approach is called TF-IDF (term frequency-inverse document frequency), which cannot be written in a few lines, so you should look into the details in references such as this wiki.

This is a classic example of operations that can be performed on vectorized concepts: king - man + woman = queen.

It is worth noting that this model does not comprehend the meaning of the words but simply tries to position the vectors such that words used in common context are close to each other.

the last fully connected layers of the network, adding new layers chosen for a specific task, and then training the network on new data.

If your task is to just vectorize the image (for example, to use some non-network classifier), you only need to remove the last layers and use the output from the previous layers: Here's a classifier trained on one dataset and adapted for a different one by "detaching"

Features generated by hand are still very useful: for example, for predicting the popularity of a rental listing, we can assume that bright apartments attract more attention and create a feature such as "the average value of the pixel".

For images, EXIF stores many useful meta-information: manufacturer and camera model, resolution, use of the flash, geographic coordinates of shooting, software used to process image and more.

Geographic data is not so often found in problems, but it is still useful to master the basic techniques for working with it, especially since there are quite a number of ready-to-use solutions in this field.

If you have a small amount of data, enough time, and no desire to extract fancy features, you can use reverse_geocoder in lieu of OpenStreetMap: When working with geoсoding, we must not forget that addresses may contain typos, which makes the data cleaning step necessary.

Coordinates contain fewer misprints, but its position can be incorrect due to GPS noise or bad accuracy in places like tunnels, downtown areas, etc.

Here, you can really unleash your imagination and invent features based on your life experience and domain knowledge: the proximity of a point to the subway, the number of stories in the building, the distance to the nearest store, the number of ATMs around, etc.

In that case, distances (great circle distance and road distance calculated by the routing graph), number of turns with the ratio of left to right turns, number of traffic lights, junctions, and bridges will be useful.

In general, when working with time series data, it is a good idea to have a calendar with public holidays, abnormal weather conditions, and other important events.

At the same time, if you encode them as categorical variables, you'll breed a large numbers of features and lose information about proximity -- the difference between 22 and 23 will be the same as the difference between 22 and 7.

This transformation preserves the distance between points, which is important for algorithms that estimate distance (kNN, SVM, k-means ...) However, the difference between such coding methods is down to the third decimal place in the metric.

Regarding time series — we will not go into too much detail here (mostly due to my personal lack of experience), but I will point you to a useful library that automatically generates features for time series.

By the way, the data from the IP-address is well combined with http_accept_language: if the user is sitting at the Chilean proxies and browser locale is ru_RU, something is unclean and worth a look in the corresponding column in the table (is_traveler_or_proxy_user).

simple example: suppose that the task is to predict the cost of an apartment from two variables — the distance from city center and the number of rooms.

But, to some extent, it protects against outliers: Another fairly popular option is MinMax Scaling, which brings all the points within a predetermined interval (typically (0, 1)).

If we assume that some data is not normally distributed but is described by the log-normal distribution, it can easily be transformed to a normal distribution: The lognormal distribution is suitable for describing salaries, price of securities, urban population, number of comments on articles on the internet, etc.

If there are a limited number of features, it is possible to generate all the possible interactions and then weed out the unnecessary ones using the techniques described in the next section.

Approaches to handling missing values are pretty straightforward: Easy-to-use library solutions sometimes suggest sticking to something like df = df.fillna(0) and not sweat the gaps.

But this is not the best solution: data preparation takes more time than building models, so thoughtless gap-filling may hide a bug in processing and damage the model.

As long as we work with toy datasets, the size of the data is not a problem, but, for real loaded production systems, hundreds of extra features will be quite tangible.

Two types of models are usually used: some “wooden” composition such as Random Forest or a linear model with Lasso regularization so that it is prone to nullify weights of weak features.

Train a model on a subset of features, store results, repeat for different subsets, and compare the quality of models to identify the best feature set.

Fix a small number N, iterate through all combinations of N features, choose the best combination, and then iterate through the combinations of (N + 1) features so that the previous best combination of features is fixed and only a single new feature is considered.

This algorithm can be reversed: start with the complete feature space and remove features one by one until it does not impair the quality of the model or until the desired number of features is reached.

- On Wednesday, September 18, 2019

**Machine Learning Data preprocessing Feature Scaling In scikitLearn-1 Part-15**

Hi Guys checkout my udemy course at just 9.99$ ..

**Use Machine Learning Explain to Discover Data Insights**

Use the Machine Learning Explain feature in Oracle Data Visualization to automatically create visualizations about your data.

**Feature Engineering with H2O - Dmitry Larko, Senior Data Scientist, H2O.ai**

This meetup has held in Mountain View on 29th November, 2017. The slides of this meetup can be found here: ...

**How Machines Learn**

How do all the algorithms around us learn to do their jobs? Bot Wallpapers on Patreon: Discuss this video: ..

**10 Secret Phone Features You’ll Start Using Right Away**

10 handy tips for iOS and Android users. Did you know that you can take photos, while you're filming a video or make your password a current time? Watch ...

**The best stats you've ever seen | Hans Rosling**

With the drama and urgency of a sportscaster, statistics guru Hans Rosling uses an amazing new presentation tool, Gapminder, to present ..

**Understanding the p-value - Statistics Help**

With Spanish subtitles. This video explains how to use the p-value to draw conclusions from statistical output. It includes the story of Helen, making sure that the ...

**Learn PHP in 15 minutes**

PHP is one of the most useful languages to know and is used everywhere you look online. In this tutorial, I start from the beginning and show you how to start ...

**MarI/O - Machine Learning for Video Games**

MarI/O is a program made of neural networks and genetic algorithms that kicks butt at Super Mario World. Source Code: "NEAT" ..

**Sampling: Simple Random, Convenience, systematic, cluster, stratified - Statistics Help**

This video describes five common methods of sampling in data collection. Each has a helpful diagrammatic representation. You might like to read my blog: ...