Commit 36dbc539 authored by Sajana_it20194130's avatar Sajana_it20194130

Upload New File

parent 356a0da0
import re
import numpy as np
from sklearn.preprocessing import StandardScaler
import joblib
# Function to extract features
def extract_features(url):
url_length = len(url)
special_chars = len(re.findall(r'[!@#$%^&*(),.?":{}|<>]', url))
return [url_length, special_chars]
# Load the best-trained text and engineered feature classifiers
best_text_classifier = joblib.load('best_text_classifier.joblib')
best_engineered_classifier = joblib.load('best_engineered_classifier.joblib')
# Create a StandardScaler instance and fit it to a placeholder example
scaler = StandardScaler()
# Placeholder example (replace with actual training data if available)
placeholder_example = np.array([[100, 5], [120, 8], [90, 3]])
# Fit the scaler to the placeholder example
scaler.fit(placeholder_example)
# Input URL from the console
new_url = input("Enter the URL to predict: ")
# Feature extraction for the new URL
new_text_features = extract_features(new_url)
# Standardize the new features using the fitted scaler
new_text_features = scaler.transform([new_text_features])
# Make predictions using the text-based classifier
text_prediction = best_text_classifier.predict([new_url])
# Make predictions using the engineered feature-based classifier
engineered_prediction = best_engineered_classifier.predict(new_text_features)
# Print predictions
print("Text-Based Prediction:", text_prediction[0])
print("Engineered Feature-Based Prediction:", engineered_prediction[0])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment