Views
No views yet
1pip install scikit-learn
2pip install -U "tensorflow-text==2.13.*"
3pip install "tf-models-official==2.13.*"
4pip uninstall -y pyarrow datasets
5pip install pyarrow datasets1from datasets import load_dataset
2from sklearn.feature_extraction.text import TfidfVectorizer
3from sklearn.linear_model import LogisticRegression
4from sklearn.model_selection import train_test_split
5from sklearn.metrics import accuracy_score
6
7# Load the dataset
8dataset_reduced = load_dataset("ealvaradob/phishing-dataset", "combined_reduced", trust_remote_code=True)
9
10# Convert to pandas DataFrame
11df = dataset_reduced['train'].to_pandas()
12
13# Extract text and labels
14text = df['text'].values
15labels = df['label'].values
16
17# Split the data into train and test sets
18train_text, test_text, train_labels, test_labels = train_test_split(
19 text, labels, test_size=0.2, random_state=42
20)
21
22# Create and fit the TF-IDF vectorizer
23vectorizer = TfidfVectorizer(max_features=5000)
24vectorizer.fit(train_text)
25
26# Transform the text data into numerical features
27train_features = vectorizer.transform(train_text)
28test_features = vectorizer.transform(test_text)
29
30# Create and train the logistic regression model
31model = LogisticRegression()
32model.fit(train_features, train_labels)
33
34# Make predictions on the test set
35predictions = model.predict(test_features)
36
37# Evaluate the model's accuracy
38accuracy = accuracy_score(test_labels, predictions)
39print(f'Accuracy: {accuracy}'){{accuracy}} on the test set.1 (phishing) and 0 (non-phishing).