टेक्स्ट एन्कोडिंग का परिचय

Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

Robert O'Callaghan

Director of Data Science, Ordergroove

अपने टेक्स्ट को मानकीकृत करें

मुक्त टेक्स्ट का उदाहरण:

Senate और House of Representatives के सहनागरिकों: जीवन की घटनाओं में से कोई भी घटना मुझे उससे अधिक चिंतित नहीं कर सकती थी जिसकी सूचना आपके आदेश से भेजी गई और इस माह की तारीख को प्राप्त हुई।

Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

डेटासेट

print(speech_df.head())
                  Name           Inaugural Address    \ 
0    George Washington     First Inaugural Address
1    George Washington    Second Inaugural Address
2    John Adams                  Inaugural Address    
3    Thomas Jefferson      First Inaugural Address    
4    Thomas Jefferson     Second Inaugural Address

                        Date                               text
0    Thursday, April 30, 1789    Fellow-Citizens of the Sena...
1       Monday, March 4, 1793    Fellow Citizens: I AM again...
2     Saturday, March 4, 1797    WHEN it was first perceived...
3    Wednesday, March 4, 1801    Friends and Fellow-Citizens...
4       Monday, March 4, 1805    PROCEEDING, fellow-citizens...
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

अनचाहे करैक्टर हटाना

  • [a-zA-Z]: सभी अक्षर करैक्टर
  • [^a-zA-Z]: सभी गैर-अक्षर करैक्टर
speech_df['text'] = speech_df['text']\
                   .str.replace('[^a-zA-Z]', ' ')
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

अनचाहे करैक्टर हटाना

पहले:

"Fellow-Citizens of the Senate and of the House of  
Representatives: AMONG the vicissitudes incident to   
life no event could have filled me with greater" ...

बाद में:

"Fellow Citizens of the Senate and of the House of  
Representatives AMONG the vicissitudes incident to   
life no event could have filled me with greater" ...
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

अक्षरों का केस मानकीकृत करें

speech_df['text'] = speech_df['text'].str.lower()
print(speech_df['text'][0])
"fellow citizens of the senate and of the house of  
representatives among the vicissitudes incident to   
life no event could have filled me with greater"...
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

टेक्स्ट की लंबाई

speech_df['char_cnt'] = speech_df['text'].str.len()
print(speech_df['char_cnt'].head())
0    1889  
1     806  
2    2408  
3    1495  
4    2465
Name: char_cnt, dtype: int64
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

शब्द गणना

speech_df['word_cnt'] = 
    speech_df['text'].str.split()
speech_df['word_cnt'].head(1)
['fellow', 'citizens', 'of', 'the', 'senate', 'and',...
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

शब्द गणना

speech_df['word_counts'] = 
    speech_df['text'].str.split().str.len()
print(speech_df['word_splits'].head())
0    1432
1     135
2    2323
3    1736
4    2169
Name: word_cnt, dtype: int64
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

औसत शब्द-लंबाई

speech_df['avg_word_len'] = 
         speech_df['char_cnt'] / speech_df['word_cnt']
Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

अभ्यास करते हैं!

Python में मशीन लर्निंग के लिए फीचर इंजीनियरिंग

Preparing Video For Download...