Cannot run it on my local environment

Course Name: Portfolio Management using Machine Learning: Hierarchical Risk Parity, Section No: 12, Unit No: 8, Unit type: Notebook

Error when run until [In7]

 

Hi,



I am not able to replicate the issue. It is working fine on my local system. It would be great if you could please share the error that you are getting while running the code, so that we can help debug the same.



Thanks,

Akshay

TypeError                                 Traceback (most recent call last)
Cell In[7], line 2
      1 # Scale the data using StandardScaler
----> 2 train_dataset_scaled = pd.DataFrame(StandardScaler().fit_transform(train_dataset),
      3                                     columns=[train_dataset.columns],
      4                                     index=train_dataset.index)

File ~\anaconda3\Lib\site-packages\sklearn\utils\_set_output.py:140, in _wrap_method_output.<locals>.wrapped(self, X, *args, **kwargs)
    138 @wraps(f)
    139 def wrapped(self, X, *args, **kwargs):
--> 140     data_to_wrap = f(self, X, *args, **kwargs)
    141     if isinstance(data_to_wrap, tuple):
    142         # only wrap the first output for cross decomposition
    143         return_tuple = (
    144             _wrap_data_with_container(method, data_to_wrap[0], X, self),
    145             *data_to_wrap[1:],
    146         )

File ~\anaconda3\Lib\site-packages\sklearn\base.py:915, in TransformerMixin.fit_transform(self, X, y, **fit_params)
    911 # non-optimized default implementation; override when a better
    912 # method is possible for a given clustering algorithm
    913 if y is None:
    914     # fit method of arity 1 (unsupervised transformation)
--> 915     return self.fit(X, **fit_params).transform(X)
    916 else:
    917     # fit method of arity 2 (supervised transformation)
    918     return self.fit(X, y, **fit_params).transform(X)

File ~\anaconda3\Lib\site-packages\sklearn\preprocessing\_data.py:837, in StandardScaler.fit(self, X, y, sample_weight)
    835 # Reset internal state before fitting
    836 self._reset()
--> 837 return self.partial_fit(X, y, sample_weight)

File ~\anaconda3\Lib\site-packages\sklearn\base.py:1151, in _fit_context.<locals>.decorator.<locals>.wrapper(estimator, *args, **kwargs)
   1144     estimator._validate_params()
   1146 with config_context(
   1147     skip_parameter_validation=(
   1148         prefer_skip_nested_validation or global_skip_validation
   1149     )
   1150 ):
-> 1151     return fit_method(estimator, *args, **kwargs)

File ~\anaconda3\Lib\site-packages\sklearn\preprocessing\_data.py:873, in StandardScaler.partial_fit(self, X, y, sample_weight)
    841 """Online computation of mean and std on X for later scaling.
    842 
    843 All of X is processed as a single batch. This is intended for cases
   (...)
    870     Fitted scaler.
    871 """
    872 first_call = not hasattr(self, "n_samples_seen_")
--> 873 X = self._validate_data(
    874     X,
    875     accept_sparse=("csr", "csc"),
    876     dtype=FLOAT_DTYPES,
    877     force_all_finite="allow-nan",
    878     reset=first_call,
    879 )
    880 n_features = X.shape[1]
    882 if sample_weight is not None:

File ~\anaconda3\Lib\site-packages\sklearn\base.py:579, in BaseEstimator._validate_data(self, X, y, reset, validate_separately, cast_to_ndarray, **check_params)
    508 def _validate_data(
    509     self,
    510     X="no_validation",
   (...)
    515     **check_params,
    516 ):
    517     """Validate input data and set or check the `n_features_in_` attribute.
    518 
    519     Parameters
   (...)
    577         validated.
    578     """
--> 579     self._check_feature_names(X, reset=reset)
    581     if y is None and self._get_tags()["requires_y"]:
    582         raise ValueError(
    583             f"This {self.__class__.__name__} estimator "
    584             "requires y to be passed, but the target y is None."
    585         )

File ~\anaconda3\Lib\site-packages\sklearn\base.py:440, in BaseEstimator._check_feature_names(self, X, reset)
    420 """Set or check the `feature_names_in_` attribute.
    421 
    422 .. versionadded:: 1.0
   (...)
    436        should set `reset=False`.
    437 """
    439 if reset:
--> 440     feature_names_in = _get_feature_names(X)
    441     if feature_names_in is not None:
    442         self.feature_names_in_ = feature_names_in

File ~\anaconda3\Lib\site-packages\sklearn\utils\validation.py:2021, in _get_feature_names(X)
   2019 # mixed type of string and non-string is not supported
   2020 if len(types) > 1 and "str" in types:
-> 2021     raise TypeError(
   2022         "Feature names are only supported if all input features have string names, "
   2023         f"but your input has {types} as feature name / column name types. "
   2024         "If you want feature names to be stored and validated, you must convert "
   2025         "them all to strings, by using X.columns = X.columns.astype(str) for "
   2026         "example. Otherwise you can remove feature / column names from your input "
   2027         "data, or convert them all to a non-string data type."
   2028     )
   2030 # Only feature names of all strings are supported
   2031 if len(types) == 1 and types[0] == "str":

TypeError: Feature names are only supported if all input features have

Hi,



The error might be due to a difference in a library version on the Quantra portal and your local system. One way to resolve it is to set up the Quantra Python environment on your system and then try running the notebook on the quantra environment. You can refer to this link to learn more about setting up the Python environment on your system. Please do let us know if you face any issues. 



Thanks,

Akshay