PerSent 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of PerSent might be problematic. Click here for more details.
- {persent-0.2.3 → persent-0.2.4}/PKG-INFO +1 -1
- {persent-0.2.3 → persent-0.2.4}/PerSent/CommentAnalyzer.py +41 -1
- {persent-0.2.3 → persent-0.2.4}/PerSent/__init__.py +1 -1
- {persent-0.2.3 → persent-0.2.4}/PerSent.egg-info/PKG-INFO +1 -1
- {persent-0.2.3 → persent-0.2.4}/setup.py +1 -1
- {persent-0.2.3 → persent-0.2.4}/PerSent.egg-info/SOURCES.txt +0 -0
- {persent-0.2.3 → persent-0.2.4}/PerSent.egg-info/dependency_links.txt +0 -0
- {persent-0.2.3 → persent-0.2.4}/PerSent.egg-info/requires.txt +0 -0
- {persent-0.2.3 → persent-0.2.4}/PerSent.egg-info/top_level.txt +0 -0
- {persent-0.2.3 → persent-0.2.4}/README.md +0 -0
- {persent-0.2.3 → persent-0.2.4}/setup.cfg +0 -0
|
@@ -112,7 +112,7 @@ class CommentAnalyzer:
|
|
|
112
112
|
self.classifier = joblib.load(os.path.join(self.model_dir, 'classifier.joblib'))
|
|
113
113
|
self.vectorizer = Word2Vec.load(os.path.join(self.model_dir, 'word2vec.model'))
|
|
114
114
|
|
|
115
|
-
def csvPredict(self, input_csv, output_path, text_column=0):
|
|
115
|
+
def csvPredict(self, input_csv, output_path, summary_path=None, text_column=0):
|
|
116
116
|
"""
|
|
117
117
|
Analyze sentiment for comments in a CSV file and save results
|
|
118
118
|
|
|
@@ -121,6 +121,8 @@ class CommentAnalyzer:
|
|
|
121
121
|
output_path (str): Path to save output CSV file
|
|
122
122
|
text_column (str/int, optional): Name or index (0-based) of column containing comments.
|
|
123
123
|
Defaults to 0 (first column).
|
|
124
|
+
summary_path (str, optional): Path to save prediction summary report.
|
|
125
|
+
If None, no summary will be saved.
|
|
124
126
|
"""
|
|
125
127
|
try:
|
|
126
128
|
# Read input CSV
|
|
@@ -149,11 +151,49 @@ class CommentAnalyzer:
|
|
|
149
151
|
df.to_csv(output_path, index=False, encoding='utf-8-sig')
|
|
150
152
|
print(f"Results saved to {output_path}")
|
|
151
153
|
|
|
154
|
+
# Generate and save summary if requested
|
|
155
|
+
if summary_path:
|
|
156
|
+
summary = self._generate_summary(df)
|
|
157
|
+
summary.to_csv(summary_path, index=False, encoding='utf-8-sig')
|
|
158
|
+
print(f"Summary report saved to {summary_path}")
|
|
159
|
+
|
|
152
160
|
return df
|
|
153
161
|
|
|
154
162
|
except Exception as e:
|
|
155
163
|
print(f"Error: {str(e)}")
|
|
156
164
|
return None
|
|
157
165
|
|
|
166
|
+
def _generate_summary(self, df):
|
|
167
|
+
"""Generate prediction summary statistics"""
|
|
168
|
+
# Count each sentiment
|
|
169
|
+
counts = df['sentiment'].value_counts().to_dict()
|
|
170
|
+
|
|
171
|
+
# Create summary dataframe
|
|
172
|
+
summary = pd.DataFrame({
|
|
173
|
+
'Category': [
|
|
174
|
+
'Recommended',
|
|
175
|
+
'Not Recommended',
|
|
176
|
+
'No Idea',
|
|
177
|
+
'Total',
|
|
178
|
+
'Model Accuracy'
|
|
179
|
+
],
|
|
180
|
+
'Count': [
|
|
181
|
+
counts.get('recommended', 0),
|
|
182
|
+
counts.get('not_recommended', 0),
|
|
183
|
+
counts.get('no_idea', 0),
|
|
184
|
+
len(df),
|
|
185
|
+
'N/A' # Accuracy needs to be calculated during training
|
|
186
|
+
],
|
|
187
|
+
'Percentage': [
|
|
188
|
+
f"{100 * counts.get('recommended', 0) / len(df):.2f}%",
|
|
189
|
+
f"{100 * counts.get('not_recommended', 0) / len(df):.2f}%",
|
|
190
|
+
f"{100 * counts.get('no_idea', 0) / len(df):.2f}%",
|
|
191
|
+
'100%',
|
|
192
|
+
'N/A'
|
|
193
|
+
]
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
return summary
|
|
197
|
+
|
|
158
198
|
|
|
159
199
|
# Github : RezaGooner
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|