[Python] UserWarning: X does not have valid feature names, but DecisionTreeClassifier was...

Discussão em 'Python' iniciado por Stack, Março 14, 2025.

  1. Stack

    Stack Membro Participativo

    I am learning machine learning from Programming with Mosh channel. I got desired output in this case.

    output=array(['HipHop', 'Acoustic', 'Classical'], dtype=object)


    but there is a warning like this and I cannot find which part is wrong.

    C:\Users\User\anaconda3\lib\site-packages\sklearn\base.py:450: UserWarning: X does not have valid feature names, but DecisionTreeClassifier was fitted with feature names
    warnings.warn(


    Do you know how can I correct this?

    Code:

    import pandas as pd
    from sklearn.tree import DecisionTreeClassifier
    music_data=pd.read_csv('C:\\Users\\User\\Desktop\\machine learning tutorial\\Python Tutorial Supplementary Materials\\music.csv')
    y=music_data['genre']
    X=music_data.drop(columns=['genre'])

    model = DecisionTreeClassifier()
    model.fit(X,y)
    predictions=model.predict([[22,1],[26,0],[39,1]])
    predictions

    Continue reading...

Compartilhe esta Página