nonzeroexit commited on
Commit
51159d5
·
verified ·
1 Parent(s): cf1d474

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -14
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("SVM.joblib")
9
- scaler = MinMaxScaler()
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
- aac = AAComposition.CalculateAADipeptideComposition(sequence) # Amino Acid Composition
41
-
 
 
 
 
 
 
42
 
43
- # Combine both feature sets
44
- all_features = aac
45
 
46
- # Extract only the selected features
47
- selected_feature_values = [all_features[feature] for feature in selected_features if feature in all_features]
 
48
 
49
- # Convert to NumPy array for normalization
50
- feature_array = np.array(selected_feature_values).reshape(-1, 1)
51
- # Min-Max Normalization
52
- scaler = MinMaxScaler()
53
- normalized_features = scaler.fit_transform(feature_array)
 
 
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):