'Unable to Vectorize categorical features
I have a dataset in this form:
Restaurant Name Online_Order Average_price Location Table_Booking Rating
Pot Au Feu Yes 65 Franklin Available 4.2
The Aviary No 42 Clinton Available 4.4
Brass Tacks Yes 29 Lebanon Not Available 4.1
This dataset has totally 40023 rows. Also, there is no missing or Null values in any columns. 'Rating' column is the class label.
Initially I have done train test split
X = data.drop('Rating',axis=1)
y = data['Rating']
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33)
Then I have separated out the categorical features so that I can vectorize all of them together.
X_train_categorical_featues = X_train[['Restaurant_Name','Online_Order','Location','Table_Booking']]
X_test_categorical_featues = X_test[['Restaurant_Name','Online_Order','Location','Table_Booking']]
Now when I tried countvectorizer on them, they are giving me wrong results.
vectorizer = CountVectorizer()
vectorizer.fit(X_train_categorical_features)
X_tr_vectorized = vectorizer.transform(X_train_categorical_features)
X_test_vectorized = vectorizer.transform(X_test_categorical_features)
When I am printing X_tr_vectorized or X_test_vectorized , they are giving me a 3*3 sparse matrix which is completely wrong because I have 40023 rows in my dataset.
Can someone please suggest that what wrong I am doing ??
Solution 1:[1]
Try this...
import { map } from 'rxjs/operators';
import { Observable } from 'rxjs';
insertRecord(form: NgForm):Observable<any> {
return this.service.postEmployee(form.value).pipe(map(((res: any[]): void=> {
this.toastr.success('Inserted successfully', 'Employee Details');
this.resetForm(form); this.service.refreshList(); }), } }
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Kibé M.C |
