from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.tree import DecisionTreeClassifier
from sklearn.model_selection import train_test_split
# Example vector of strings
vector_of_strings = [
"This is the first string",
"Another string to process",
"Final string for the example"
]
labels = [0, 1, 0] # Example labels for classification
# Initialize TF-IDF vectorizer
vectorizer = TfidfVectorizer()
# Fit and transform the vector of strings
X = vectorizer.fit_transform(vector_of_strings)
# Split data into train and test sets
X_train, X_test, y_train, y_test = train_test_split(X, labels, test_size=0.2, random_state=42)
# Initialize decision tree classifier
clf = DecisionTreeClassifier()
# Train the classifier
clf.fit(X_train, y_train)
# Predict on test data
y_pred = clf.predict(X_test)
# Evaluate accuracy or other metrics
accuracy = clf.score(X_test, y_test)
print(f"Accuracy: {accuracy}")