I have imported the titanic.csv file and clean the file , when i wanna fit it to the Logistic Regression it cause the error and it wisent solving
Can Anyone help to solve this problem??
*Survived Age SibSp Parch Fare male Q S 2 3
0 0 22.0 1 0 7.2500 1 0 1 0 1
1 1 38.0 1 0 71.2833 0 0 0 0 0
2 1 26.0 0 0 7.9250 0 0 1 0 1
3 1 35.0 1 0 53.1000 0 0 1 0 0
4 0 35.0 0 0 8.0500 1 0 1 0 1*
i cleaned the data like this and perform this code in it
X= titanic_data.drop("Survived", axis = 1)
y= titanic_data["Survived"]
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.3, random_state=1)
from sklearn.linear_model import LogisticRegression
logmodels = LogisticRegression(random_state=1)
logmodels.fit(X_train, y_train)
while compiling the last line i got the error like this
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-45-05d5668a869d> in <cell line: 2>()
```
1 logmodels = LogisticRegression(random_state=1)
----> 2 logmodels.fit(X_train, y_train)
```
3 frames
/usr/local/lib/python3.10/dist-packages/sklearn/utils/validation.py in _get_feature_names(X)
1901 # mixed type of string and non-string is not supported
1902 if len(types) > 1 and "str" in types:
-> 1903 raise TypeError(
1904 "Feature names are only supported if all input features have string names, "
1905 f"but your input has {types} as feature name / column name types. "
TypeError: Feature names are only supported if all input features have string names, but your input has ['int', 'str'] as feature name / column name types. If you want feature names to be stored and validated, you must convert them all to strings, by using X.columns = X.columns.astype(str) for example. Otherwise you can remove feature / column names from your input data, or convert them all to a non-string data type.