Project - Working with Custom Loss Function

2 / 6

Preparing the Dataset

Let's start by loading and preparing the California housing dataset.

We would:

  • first load the data

  • then split it into a training set, a validation set, and a test set

  • finally, we scale it.

Note that this dataset contains only numerical features and there are no missing values.

Note:

  • For a feature scaler like StandardScaler, fit computes the mean and std(standard deviation) to be used for later scaling (just a computation) based on the given data, nothing is given to you. transform uses a previously computed mean and std to autoscale the data (subtract mean from all values and then divide it by std). fit_transform does both at the same time.

  • So, we would be applying the scaler.fit_transform on the train data, and just apply scaler.transform on the validation and test data.

INSTRUCTIONS
  • Import fetch_california_housing from sklearn.datasets.

    from << your code comes here >> import << your code comes here >>
    
  • Use fetch_california_housing() we imported from sklearn.datasets to load the data.

    housing = << your code comes here >>()
    
  • Import train_test_split from sklearn.model_selection.

    from << your code comes here >> import << your code comes here >>
    
  • Split the data into a training set, a validation set, and a test set using train_test_split.

    X_train_full, X_test, y_train_full, y_test = << your code comes here >>( housing.data,
             housing.target.reshape(-1, 1), random_state=42)
    
    X_train, X_valid, y_train, y_valid =  << your code comes here >>( X_train_full, 
            y_train_full, random_state=42)
    
  • Import StandardScaler from sklearn.preprocessing.

    from << your code comes here >> import << your code comes here >>
    
  • Use StandardScaler to get scaler.

    scaler = << your code comes here >>()
    
  • Scale all the train, validation, and test features.

    • Use scaler.fit_transform on X_train and store it in X_train_scaled.

      X_train_scaled = << your code comes here >>(X_train)
      
    • Use scaler.transform on X_valid and store it in X_valid_scaled.

      X_valid_scaled = << your code comes here >>(X_valid)
      
    • Use scaler.transform on X_test and store it in X_test_scaled.

      X_test_scaled = << your code comes here >>(X_test)
      
Get Hint See Answer


Note - Having trouble with the assessment engine? Follow the steps listed here

Loading comments...