featrixsphere 0.2.6127__py3-none-any.whl → 0.2.6379__py3-none-any.whl
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.
- featrixsphere/__init__.py +1 -1
- featrixsphere/client.py +54 -42
- {featrixsphere-0.2.6127.dist-info → featrixsphere-0.2.6379.dist-info}/METADATA +1 -1
- {featrixsphere-0.2.6127.dist-info → featrixsphere-0.2.6379.dist-info}/RECORD +7 -7
- {featrixsphere-0.2.6127.dist-info → featrixsphere-0.2.6379.dist-info}/WHEEL +1 -1
- {featrixsphere-0.2.6127.dist-info → featrixsphere-0.2.6379.dist-info}/entry_points.txt +0 -0
- {featrixsphere-0.2.6127.dist-info → featrixsphere-0.2.6379.dist-info}/top_level.txt +0 -0
featrixsphere/__init__.py
CHANGED
featrixsphere/client.py
CHANGED
|
@@ -137,22 +137,24 @@ class SessionInfo:
|
|
|
137
137
|
class PredictionBatch:
|
|
138
138
|
"""
|
|
139
139
|
Cached prediction batch that allows instant lookups after initial batch processing.
|
|
140
|
-
|
|
140
|
+
|
|
141
141
|
Usage:
|
|
142
142
|
# First run - populate cache
|
|
143
143
|
batch = client.predict_batch(session_id, records)
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
# Second run - instant cache lookups
|
|
146
146
|
for i in values1:
|
|
147
147
|
for j in values2:
|
|
148
148
|
record = {"param1": i, "param2": j}
|
|
149
149
|
result = batch.predict(record) # Instant!
|
|
150
150
|
"""
|
|
151
|
-
|
|
152
|
-
def __init__(self, session_id: str, client: 'FeatrixSphereClient', target_column: str = None
|
|
151
|
+
|
|
152
|
+
def __init__(self, session_id: str, client: 'FeatrixSphereClient', target_column: str = None,
|
|
153
|
+
best_metric_preference: str = None):
|
|
153
154
|
self.session_id = session_id
|
|
154
155
|
self.client = client
|
|
155
156
|
self.target_column = target_column
|
|
157
|
+
self.best_metric_preference = best_metric_preference
|
|
156
158
|
self._cache = {} # record_hash -> prediction_result
|
|
157
159
|
self._stats = {'hits': 0, 'misses': 0, 'populated': 0}
|
|
158
160
|
|
|
@@ -203,14 +205,15 @@ class PredictionBatch:
|
|
|
203
205
|
"""Populate the cache with batch predictions."""
|
|
204
206
|
if not records:
|
|
205
207
|
return {'summary': {'total_records': 0, 'successful': 0, 'failed': 0}}
|
|
206
|
-
|
|
208
|
+
|
|
207
209
|
print(f"🚀 Creating prediction batch for {len(records)} records...")
|
|
208
|
-
|
|
210
|
+
|
|
209
211
|
# Use existing batch prediction system
|
|
210
212
|
batch_results = self.client.predict_records(
|
|
211
213
|
session_id=self.session_id,
|
|
212
214
|
records=records,
|
|
213
215
|
target_column=self.target_column,
|
|
216
|
+
best_metric_preference=self.best_metric_preference,
|
|
214
217
|
show_progress_bar=True
|
|
215
218
|
)
|
|
216
219
|
|
|
@@ -7744,23 +7747,25 @@ class FeatrixSphereClient:
|
|
|
7744
7747
|
else:
|
|
7745
7748
|
return data
|
|
7746
7749
|
|
|
7747
|
-
def predict_csv_file(self, session_id: str, file_path: Path
|
|
7750
|
+
def predict_csv_file(self, session_id: str, file_path: Path,
|
|
7751
|
+
best_metric_preference: str = None) -> Dict[str, Any]:
|
|
7748
7752
|
"""
|
|
7749
7753
|
Make batch predictions on a CSV file.
|
|
7750
|
-
|
|
7754
|
+
|
|
7751
7755
|
Args:
|
|
7752
7756
|
session_id: ID of session with trained predictor
|
|
7753
7757
|
file_path: Path to CSV file
|
|
7754
|
-
|
|
7758
|
+
best_metric_preference: Which metric checkpoint to use: "roc_auc", "pr_auc", or None (default)
|
|
7759
|
+
|
|
7755
7760
|
Returns:
|
|
7756
7761
|
Batch prediction results
|
|
7757
7762
|
"""
|
|
7758
7763
|
import pandas as pd
|
|
7759
7764
|
from jsontables import JSONTablesEncoder
|
|
7760
|
-
|
|
7765
|
+
|
|
7761
7766
|
if not file_path.exists():
|
|
7762
7767
|
raise FileNotFoundError(f"File not found: {file_path}")
|
|
7763
|
-
|
|
7768
|
+
|
|
7764
7769
|
# Support CSV, Parquet, JSON, and JSONL files
|
|
7765
7770
|
file_path_str = str(file_path).lower()
|
|
7766
7771
|
if file_path_str.endswith('.parquet'):
|
|
@@ -7779,29 +7784,31 @@ class FeatrixSphereClient:
|
|
|
7779
7784
|
df = pd.read_json(file_path)
|
|
7780
7785
|
else:
|
|
7781
7786
|
df = pd.read_csv(file_path)
|
|
7782
|
-
|
|
7787
|
+
|
|
7783
7788
|
# Convert to JSON Tables format and clean NaNs
|
|
7784
7789
|
table_data = JSONTablesEncoder.from_dataframe(df)
|
|
7785
7790
|
cleaned_table_data = self.replace_nans_with_nulls(table_data)
|
|
7786
|
-
|
|
7787
|
-
return self.predict_table(session_id, cleaned_table_data)
|
|
7788
7791
|
|
|
7789
|
-
|
|
7792
|
+
return self.predict_table(session_id, cleaned_table_data, best_metric_preference=best_metric_preference)
|
|
7793
|
+
|
|
7794
|
+
def run_predictions(self, session_id: str, records: List[Dict[str, Any]],
|
|
7795
|
+
best_metric_preference: str = None) -> Dict[str, Any]:
|
|
7790
7796
|
"""
|
|
7791
7797
|
Run predictions on provided records. Clean and fast for production use.
|
|
7792
|
-
|
|
7798
|
+
|
|
7793
7799
|
Args:
|
|
7794
7800
|
session_id: ID of session with trained predictor
|
|
7795
7801
|
records: List of record dictionaries
|
|
7796
|
-
|
|
7802
|
+
best_metric_preference: Which metric checkpoint to use: "roc_auc", "pr_auc", or None (default)
|
|
7803
|
+
|
|
7797
7804
|
Returns:
|
|
7798
7805
|
Dictionary with prediction results
|
|
7799
7806
|
"""
|
|
7800
7807
|
# Clean NaNs for JSON encoding
|
|
7801
7808
|
cleaned_records = self.replace_nans_with_nulls(records)
|
|
7802
|
-
|
|
7809
|
+
|
|
7803
7810
|
# Make batch predictions
|
|
7804
|
-
batch_results = self.predict_records(session_id, cleaned_records)
|
|
7811
|
+
batch_results = self.predict_records(session_id, cleaned_records, best_metric_preference=best_metric_preference)
|
|
7805
7812
|
predictions = batch_results['predictions']
|
|
7806
7813
|
|
|
7807
7814
|
# Process predictions into clean format
|
|
@@ -8517,32 +8524,33 @@ class FeatrixSphereClient:
|
|
|
8517
8524
|
|
|
8518
8525
|
return cleared_counts
|
|
8519
8526
|
|
|
8520
|
-
def predict_batch(self, session_id: str, records: List[Dict[str, Any]],
|
|
8521
|
-
|
|
8527
|
+
def predict_batch(self, session_id: str, records: List[Dict[str, Any]],
|
|
8528
|
+
target_column: str = None, best_metric_preference: str = None) -> PredictionBatch:
|
|
8522
8529
|
"""
|
|
8523
8530
|
Create a prediction batch for instant cached lookups.
|
|
8524
|
-
|
|
8531
|
+
|
|
8525
8532
|
Perfect for parameter sweeps, grid searches, and exploring prediction surfaces.
|
|
8526
8533
|
Run your loops twice with identical code - first populates cache, second gets instant results.
|
|
8527
|
-
|
|
8534
|
+
|
|
8528
8535
|
Args:
|
|
8529
8536
|
session_id: ID of session with trained predictor
|
|
8530
8537
|
records: List of all records you'll want to predict on
|
|
8531
8538
|
target_column: Specific target column predictor to use
|
|
8532
|
-
|
|
8539
|
+
best_metric_preference: Which metric checkpoint to use: "roc_auc", "pr_auc", or None (default)
|
|
8540
|
+
|
|
8533
8541
|
Returns:
|
|
8534
8542
|
PredictionBatch object with instant predict() method
|
|
8535
|
-
|
|
8543
|
+
|
|
8536
8544
|
Example:
|
|
8537
8545
|
# Generate all combinations you'll need
|
|
8538
8546
|
records = []
|
|
8539
8547
|
for i in range(10):
|
|
8540
8548
|
for j in range(10):
|
|
8541
8549
|
records.append({"param1": i, "param2": j})
|
|
8542
|
-
|
|
8550
|
+
|
|
8543
8551
|
# First run - populate cache with batch processing
|
|
8544
8552
|
batch = client.predict_batch(session_id, records)
|
|
8545
|
-
|
|
8553
|
+
|
|
8546
8554
|
# Second run - same loops but instant cache lookups
|
|
8547
8555
|
results = []
|
|
8548
8556
|
for i in range(10):
|
|
@@ -8552,50 +8560,52 @@ class FeatrixSphereClient:
|
|
|
8552
8560
|
results.append(result)
|
|
8553
8561
|
"""
|
|
8554
8562
|
# Create batch object
|
|
8555
|
-
batch = PredictionBatch(session_id, self, target_column)
|
|
8556
|
-
|
|
8563
|
+
batch = PredictionBatch(session_id, self, target_column, best_metric_preference)
|
|
8564
|
+
|
|
8557
8565
|
# Populate cache with batch predictions
|
|
8558
8566
|
batch._populate_cache(records)
|
|
8559
|
-
|
|
8567
|
+
|
|
8560
8568
|
return batch
|
|
8561
8569
|
|
|
8562
|
-
def predict_grid(self, session_id: str, degrees_of_freedom: int,
|
|
8563
|
-
|
|
8570
|
+
def predict_grid(self, session_id: str, degrees_of_freedom: int,
|
|
8571
|
+
grid_shape: tuple = None, target_column: str = None,
|
|
8572
|
+
best_metric_preference: str = None) -> 'PredictionGrid':
|
|
8564
8573
|
"""
|
|
8565
8574
|
Create a prediction grid for exploring parameter surfaces with automatic visualization.
|
|
8566
|
-
|
|
8575
|
+
|
|
8567
8576
|
Perfect for 1D curves, 2D heatmaps, and 3D surfaces with built-in plotting functions.
|
|
8568
|
-
|
|
8577
|
+
|
|
8569
8578
|
Args:
|
|
8570
8579
|
session_id: ID of session with trained predictor
|
|
8571
8580
|
degrees_of_freedom: Number of dimensions (1, 2, or 3)
|
|
8572
8581
|
grid_shape: Custom grid shape tuple (default: auto-sized)
|
|
8573
8582
|
target_column: Specific target column predictor to use
|
|
8574
|
-
|
|
8583
|
+
best_metric_preference: Which metric checkpoint to use: "roc_auc", "pr_auc", or None (default)
|
|
8584
|
+
|
|
8575
8585
|
Returns:
|
|
8576
8586
|
PredictionGrid object with predict() and plotting methods
|
|
8577
|
-
|
|
8587
|
+
|
|
8578
8588
|
Example:
|
|
8579
8589
|
# 2D parameter sweep with automatic plotting
|
|
8580
8590
|
grid = client.predict_grid(session_id, degrees_of_freedom=2)
|
|
8581
8591
|
grid.set_axis_labels(["Spend", "Campaign Type"])
|
|
8582
8592
|
grid.set_axis_values(0, [100, 250, 500])
|
|
8583
8593
|
grid.set_axis_values(1, ["search", "display", "social"])
|
|
8584
|
-
|
|
8594
|
+
|
|
8585
8595
|
for i, spend in enumerate([100, 250, 500]):
|
|
8586
8596
|
for j, campaign in enumerate(["search", "display", "social"]):
|
|
8587
8597
|
record = {"spend": spend, "campaign_type": campaign}
|
|
8588
8598
|
grid.predict(record, grid_position=(i, j))
|
|
8589
|
-
|
|
8599
|
+
|
|
8590
8600
|
# Automatic visualization
|
|
8591
8601
|
grid.plot_heatmap() # 2D heatmap
|
|
8592
8602
|
grid.plot_3d() # 3D surface
|
|
8593
|
-
|
|
8603
|
+
|
|
8594
8604
|
# Find optimal parameters
|
|
8595
8605
|
optimal_pos = grid.get_optimal_position()
|
|
8596
8606
|
print(f"Optimal parameters at grid position: {optimal_pos}")
|
|
8597
8607
|
"""
|
|
8598
|
-
return PredictionGrid(session_id, self, degrees_of_freedom, grid_shape, target_column)
|
|
8608
|
+
return PredictionGrid(session_id, self, degrees_of_freedom, grid_shape, target_column, best_metric_preference)
|
|
8599
8609
|
|
|
8600
8610
|
def get_embedding_space_columns(self, session_id: str) -> Dict[str, Any]:
|
|
8601
8611
|
"""
|
|
@@ -8672,12 +8682,13 @@ class PredictionGrid:
|
|
|
8672
8682
|
grid.plot_3d() # 3D surface plot
|
|
8673
8683
|
"""
|
|
8674
8684
|
|
|
8675
|
-
def __init__(self, session_id: str, client: 'FeatrixSphereClient', degrees_of_freedom: int,
|
|
8676
|
-
grid_shape: tuple = None, target_column: str = None):
|
|
8685
|
+
def __init__(self, session_id: str, client: 'FeatrixSphereClient', degrees_of_freedom: int,
|
|
8686
|
+
grid_shape: tuple = None, target_column: str = None, best_metric_preference: str = None):
|
|
8677
8687
|
self.session_id = session_id
|
|
8678
8688
|
self.client = client
|
|
8679
8689
|
self.degrees_of_freedom = degrees_of_freedom
|
|
8680
8690
|
self.target_column = target_column
|
|
8691
|
+
self.best_metric_preference = best_metric_preference
|
|
8681
8692
|
|
|
8682
8693
|
# Initialize grid matrix based on degrees of freedom
|
|
8683
8694
|
if grid_shape:
|
|
@@ -8769,6 +8780,7 @@ class PredictionGrid:
|
|
|
8769
8780
|
session_id=self.session_id,
|
|
8770
8781
|
records=records_list,
|
|
8771
8782
|
target_column=self.target_column,
|
|
8783
|
+
best_metric_preference=self.best_metric_preference,
|
|
8772
8784
|
show_progress_bar=show_progress
|
|
8773
8785
|
)
|
|
8774
8786
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
featrixsphere/__init__.py,sha256=
|
|
2
|
-
featrixsphere/client.py,sha256=
|
|
1
|
+
featrixsphere/__init__.py,sha256=m4FTeSot2GaITV5l_kD5WrSPZKdKmVbcmRwXZE_nYJk,2190
|
|
2
|
+
featrixsphere/client.py,sha256=Nj6C_Th4jyK7JQIXUJ_URok9AA0OND6DOAjoFbKhs2Q,452098
|
|
3
3
|
featrixsphere/api/__init__.py,sha256=quyvuPphVj9wb6v8Dio0SMG9iHgJAmY3asHk3f_zF10,1269
|
|
4
4
|
featrixsphere/api/api_endpoint.py,sha256=i3eCWuaUXftnH1Ai6MFZ7md7pC2FcRAIRO87CBZhyEQ,9000
|
|
5
5
|
featrixsphere/api/client.py,sha256=TdpujNsJxO4GfPMI_KoemQWV89go3KuK6OPAo9jX6Bs,12574
|
|
@@ -10,8 +10,8 @@ featrixsphere/api/prediction_result.py,sha256=Tx7LXzF4XT-U3VqAN_IFc5DvxPnygc78M2
|
|
|
10
10
|
featrixsphere/api/predictor.py,sha256=-vwCKpCfTgZKqzpDnzy1iYZQ-1-MGW8aErvxM9trktw,17652
|
|
11
11
|
featrixsphere/api/reference_record.py,sha256=-XOTF6ynznB3ouz06w3AF8X9SVId0g_dO20VvGNesUQ,7095
|
|
12
12
|
featrixsphere/api/vector_database.py,sha256=BplxKkPnAbcBX1A4KxFBJVb3qkQ-FH9zi9v2dWG5CgY,7976
|
|
13
|
-
featrixsphere-0.2.
|
|
14
|
-
featrixsphere-0.2.
|
|
15
|
-
featrixsphere-0.2.
|
|
16
|
-
featrixsphere-0.2.
|
|
17
|
-
featrixsphere-0.2.
|
|
13
|
+
featrixsphere-0.2.6379.dist-info/METADATA,sha256=EdpmIuyoX1hr1eelFuZbN-zOwrsIsN9TupOeehDJxys,16232
|
|
14
|
+
featrixsphere-0.2.6379.dist-info/WHEEL,sha256=qELbo2s1Yzl39ZmrAibXA2jjPLUYfnVhUNTlyF1rq0Y,92
|
|
15
|
+
featrixsphere-0.2.6379.dist-info/entry_points.txt,sha256=QreJeYfD_VWvbEqPmMXZ3pqqlFlJ1qZb-NtqnyhEldc,51
|
|
16
|
+
featrixsphere-0.2.6379.dist-info/top_level.txt,sha256=AyN4wjfzlD0hWnDieuEHX0KckphIk_aC73XCG4df5uU,14
|
|
17
|
+
featrixsphere-0.2.6379.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|