ValueError: Found arrays with inconsistent numbers of samples [1,299]
Question: Here is data files
[here](https://d3c33hcgiwev3.cloudfront.net/_3e251a91db9262835c9e5855ae9e6573_perceptron-
test.csv?Expires=1454976000&Signature=Qn~RxsR1tlP2pruLzkiIaAVO988Q2RaY1A9DEOINYYSJGRtX7pssvFc-09rbyWLwGrzdaAg5wAf0dXWyA6DPaJ2cBjcKu3iris~TuAR4liGjj2uFaV6pFdAYgrpXaLKNpOe5J~J3l7LZJ4qz7Sp3Prm0EQuFAGf5hsf0OErAmvs_&Key-
Pair-Id=APKAJLTNE6QMUY6HBC5A) and
[here](https://d3c33hcgiwev3.cloudfront.net/_3e251a91db9262835c9e5855ae9e6573_perceptron-
train.csv?Expires=1454976000&Signature=LRNSab2UYWhM7JdvEz3NkT6YDKZBnP-OhM-
hyGGOKXxrvoyywj4VVhP8j3wQmFacR5vnhNeNNKcaQHbnX1OB8CmVDVg074Y79OwBcdAwbkyVd2FWYRIdQXRZ2lURrRIaPSI-
NPUpcO6KAb0WHeqYbqo-lC91qrm0yG4Hemvy7ZQ_&Key-Pair-Id=APKAJLTNE6QMUY6HBC5A).
You can download it by clicking on links the link. I am using Pandas, Numpy
and Python3.

Here is my code:

    
    
    import pandas as pa
    import numpy as nu
    from sklearn.linear_model import Perceptron
    from sklearn.metrics import accuracy_score
    from sklearn.preprocessing import StandardScaler
    
    def get_accuracy(X_train, y_train, X_test, y_test):
        perceptron = Perceptron()
        perceptron.fit(X_train, y_train)
        perceptron.transform(X_train)
        prediction = perceptron.predict(X_test)
        result = accuracy_score(y_test, prediction)
        return result
    
    test_data = pa.read_csv("C:/Users/Roman/Downloads/perceptron-test.csv")
    test_data.columns = ["class", "f1", "f2"]
    train_data = pa.read_csv("C:/Users/Roman/Downloads/perceptron-train.csv")
    train_data.columns = ["class", "f1", "f2"]
    
    scaler = StandardScaler()
    scaler.fit_transform(train_data[train_data.columns[1:]]).reshape(-1,1)
    X_train = scaler.transform(train_data[train_data.columns[1:]])
    
    scaler.fit_transform(train_data[train_data.columns[0]])
    y_train = scaler.transform(train_data[train_data.columns[0]])
    
    scaler.fit_transform(test_data[test_data.columns[1:]])
    X_test = scaler.transform(test_data[test_data.columns[1:]])
    
    scaler.fit_transform(test_data[test_data.columns[0]])
    y_test = scaler.transform(test_data[test_data.columns[0]])
    
    
    
    
    scaled_accuracy = get_accuracy(nu.ravel(X_train), nu.ravel(y_train),    nu.ravel(X_test), nu.ravel(y_test))
    print(scaled_accuracy)
    

And here is error that I get:

    
    
    Traceback (most recent call last):
      File "C:/Users/Roman/PycharmProjects/data_project-1/lecture_2_perceptron.py", line 33, in <module>
        scaled_accuracy = get_accuracy(nu.ravel(X_train), nu.ravel(y_train), nu.ravel(X_test), nu.ravel(y_test))
      File "C:/Users/Roman/PycharmProjects/data_project-1/lecture_2_perceptron.py", line 9, in get_accuracy
        perceptron.fit(X_train, y_train)
      File "C:\Users\Roman\AppData\Roaming\Python\Python35\site-packages\sklearn\linear_model\stochastic_gradient.py", line 545, in fit
        sample_weight=sample_weight)
      File "C:\Users\Roman\AppData\Roaming\Python\Python35\site-packages\sklearn\linear_model\stochastic_gradient.py", line 389, in _fit
        X, y = check_X_y(X, y, 'csr', dtype=np.float64, order="C")
      File "C:\Users\Roman\AppData\Roaming\Python\Python35\site-packages\sklearn\utils\validation.py", line 520, in check_X_y
        check_consistent_length(X, y)
      File "C:\Users\Roman\AppData\Roaming\Python\Python35\site-packages\sklearn\utils\validation.py", line 176, in check_consistent_length
        "%s" % str(uniques))
    **ValueError: Found arrays with inconsistent numbers of samples: [  1 299]**
    

Without scaling data everything work fine. But after scaling not.


Answer: You should not call `fit_transform` each time you use scaler. You should `fit`
it once, on the training data, and later only `transform`, otherwise you get
different representation for training and testing (leading to error provided).
There is also no point in scaling labels.

