Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -5,8 +5,8 @@ from propy import AAComposition
|
|
5 |
from sklearn.preprocessing import MinMaxScaler
|
6 |
|
7 |
# Load trained SVM model and scaler (Ensure both files exist in the Space)
|
8 |
-
model = joblib.load("
|
9 |
-
scaler =
|
10 |
|
11 |
|
12 |
# List of features used in your model
|
@@ -37,22 +37,30 @@ selected_features = [
|
|
37 |
def extract_features(sequence):
|
38 |
"""Extract only the required features and normalize them."""
|
39 |
# Compute all possible features
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
|
46 |
-
#
|
47 |
-
|
|
|
48 |
|
49 |
-
# Convert to
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
|
|
|
|
54 |
|
55 |
-
return normalized_features
|
56 |
|
57 |
|
58 |
def predict(sequence):
|
|
|
5 |
from sklearn.preprocessing import MinMaxScaler
|
6 |
|
7 |
# Load trained SVM model and scaler (Ensure both files exist in the Space)
|
8 |
+
model = joblib.load("SVM1.joblib")
|
9 |
+
scaler = joblib.load("norm.joblib")
|
10 |
|
11 |
|
12 |
# List of features used in your model
|
|
|
37 |
def extract_features(sequence):
|
38 |
"""Extract only the required features and normalize them."""
|
39 |
# Compute all possible features
|
40 |
+
all_features = AAComposition.CalculateAADipeptideComposition(sequence) # Amino Acid Composition
|
41 |
+
# Extract the values from the dictionary
|
42 |
+
feature_values = list(all_features.values()) # Extract values only
|
43 |
+
# Convert to NumPy array for normalization
|
44 |
+
feature_array = np.array(feature_values).reshape(-1, 1)
|
45 |
+
feature_array = feature_array[: 420]
|
46 |
+
# Min-Max Normalization
|
47 |
+
normalized_features = scaler.transform(feature_array.T)
|
48 |
|
49 |
+
# Reshape normalized_features back to a single dimension
|
50 |
+
normalized_features = normalized_features.flatten() # Flatten array
|
51 |
|
52 |
+
# Create a dictionary with selected features
|
53 |
+
selected_feature_dict = {feature: normalized_features[i] for i, feature in enumerate(selected_features)
|
54 |
+
if feature in all_features}
|
55 |
|
56 |
+
# Convert dictionary to dataframe
|
57 |
+
selected_feature_df = pd.DataFrame([selected_feature_dict])
|
58 |
+
|
59 |
+
# Convert dataframe to numpy array
|
60 |
+
selected_feature_array = selected_feature_df.T.to_numpy()
|
61 |
+
|
62 |
+
return selected_feature_array
|
63 |
|
|
|
64 |
|
65 |
|
66 |
def predict(sequence):
|