@@ -413,16 +413,17 @@ def fit(self, X, y, sample_weight=None):
413
413
414
414
# initialize raw_predictions: those are the accumulated values
415
415
# predicted by the trees for the training data. raw_prediction has
416
- # shape (n_trees_per_iteration, n_samples ) where
416
+ # shape (n_samples, n_trees_per_iteration ) where
417
417
# n_trees_per_iterations is n_classes in multiclass classification,
418
418
# else 1.
419
- # self._baseline_prediction has shape (n_trees_per_iteration, 1 )
419
+ # self._baseline_prediction has shape (1, n_trees_per_iteration )
420
420
self ._baseline_prediction = self ._loss .fit_intercept_only (
421
421
y_true = y_train , sample_weight = sample_weight_train
422
- ).reshape ((- 1 , 1 ))
422
+ ).reshape ((1 , - 1 ))
423
423
raw_predictions = np .zeros (
424
- shape = (self .n_trees_per_iteration_ , n_samples ),
424
+ shape = (n_samples , self .n_trees_per_iteration_ ),
425
425
dtype = self ._baseline_prediction .dtype ,
426
+ order = "F" ,
426
427
)
427
428
raw_predictions += self ._baseline_prediction
428
429
@@ -452,8 +453,9 @@ def fit(self, X, y, sample_weight=None):
452
453
453
454
if self ._use_validation_data :
454
455
raw_predictions_val = np .zeros (
455
- shape = (self . n_trees_per_iteration_ , X_binned_val .shape [0 ]),
456
+ shape = (X_binned_val .shape [0 ], self . n_trees_per_iteration_ ),
456
457
dtype = self ._baseline_prediction .dtype ,
458
+ order = "F" ,
457
459
)
458
460
459
461
raw_predictions_val += self ._baseline_prediction
@@ -553,15 +555,15 @@ def fit(self, X, y, sample_weight=None):
553
555
if self ._loss .constant_hessian :
554
556
self ._loss .gradient (
555
557
y_true = y_train ,
556
- raw_prediction = raw_predictions . T ,
558
+ raw_prediction = raw_predictions ,
557
559
sample_weight = sample_weight_train ,
558
560
gradient_out = gradient ,
559
561
n_threads = n_threads ,
560
562
)
561
563
else :
562
564
self ._loss .gradient_hessian (
563
565
y_true = y_train ,
564
- raw_prediction = raw_predictions . T ,
566
+ raw_prediction = raw_predictions ,
565
567
sample_weight = sample_weight_train ,
566
568
gradient_out = gradient ,
567
569
hessian_out = hessian ,
@@ -609,7 +611,7 @@ def fit(self, X, y, sample_weight=None):
609
611
loss = self ._loss ,
610
612
grower = grower ,
611
613
y_true = y_train ,
612
- raw_prediction = raw_predictions [k , : ],
614
+ raw_prediction = raw_predictions [:, k ],
613
615
sample_weight = sample_weight_train ,
614
616
)
615
617
@@ -621,7 +623,7 @@ def fit(self, X, y, sample_weight=None):
621
623
# Update raw_predictions with the predictions of the newly
622
624
# created tree.
623
625
tic_pred = time ()
624
- _update_raw_predictions (raw_predictions [k , : ], grower , n_threads )
626
+ _update_raw_predictions (raw_predictions [:, k ], grower , n_threads )
625
627
toc_pred = time ()
626
628
acc_prediction_time += toc_pred - tic_pred
627
629
@@ -631,7 +633,7 @@ def fit(self, X, y, sample_weight=None):
631
633
# Update raw_predictions_val with the newest tree(s)
632
634
if self ._use_validation_data :
633
635
for k , pred in enumerate (self ._predictors [- 1 ]):
634
- raw_predictions_val [k , : ] += pred .predict_binned (
636
+ raw_predictions_val [:, k ] += pred .predict_binned (
635
637
X_binned_val ,
636
638
self ._bin_mapper .missing_values_bin_idx_ ,
637
639
n_threads ,
@@ -804,7 +806,7 @@ def _check_early_stopping_loss(
804
806
self .train_score_ .append (
805
807
- self ._loss (
806
808
y_true = y_train ,
807
- raw_prediction = raw_predictions . T ,
809
+ raw_prediction = raw_predictions ,
808
810
sample_weight = sample_weight_train ,
809
811
n_threads = n_threads ,
810
812
)
@@ -814,7 +816,7 @@ def _check_early_stopping_loss(
814
816
self .validation_score_ .append (
815
817
- self ._loss (
816
818
y_true = y_val ,
817
- raw_prediction = raw_predictions_val . T ,
819
+ raw_prediction = raw_predictions_val ,
818
820
sample_weight = sample_weight_val ,
819
821
n_threads = n_threads ,
820
822
)
@@ -928,7 +930,7 @@ def _raw_predict(self, X, n_threads=None):
928
930
929
931
Returns
930
932
-------
931
- raw_predictions : array, shape (n_trees_per_iteration, n_samples )
933
+ raw_predictions : array, shape (n_samples, n_trees_per_iteration )
932
934
The raw predicted values.
933
935
"""
934
936
is_binned = getattr (self , "_in_fit" , False )
@@ -942,8 +944,9 @@ def _raw_predict(self, X, n_threads=None):
942
944
)
943
945
n_samples = X .shape [0 ]
944
946
raw_predictions = np .zeros (
945
- shape = (self .n_trees_per_iteration_ , n_samples ),
947
+ shape = (n_samples , self .n_trees_per_iteration_ ),
946
948
dtype = self ._baseline_prediction .dtype ,
949
+ order = "F" ,
947
950
)
948
951
raw_predictions += self ._baseline_prediction
949
952
@@ -979,7 +982,7 @@ def _predict_iterations(self, X, predictors, raw_predictions, is_binned, n_threa
979
982
f_idx_map = f_idx_map ,
980
983
n_threads = n_threads ,
981
984
)
982
- raw_predictions [k , : ] += predict (X )
985
+ raw_predictions [:, k ] += predict (X )
983
986
984
987
def _staged_raw_predict (self , X ):
985
988
"""Compute raw predictions of ``X`` for each iteration.
@@ -995,7 +998,7 @@ def _staged_raw_predict(self, X):
995
998
Yields
996
999
-------
997
1000
raw_predictions : generator of ndarray of shape \
998
- (n_trees_per_iteration, n_samples )
1001
+ (n_samples, n_trees_per_iteration )
999
1002
The raw predictions of the input samples. The order of the
1000
1003
classes corresponds to that in the attribute :term:`classes_`.
1001
1004
"""
@@ -1008,8 +1011,9 @@ def _staged_raw_predict(self, X):
1008
1011
)
1009
1012
n_samples = X .shape [0 ]
1010
1013
raw_predictions = np .zeros (
1011
- shape = (self .n_trees_per_iteration_ , n_samples ),
1014
+ shape = (n_samples , self .n_trees_per_iteration_ ),
1012
1015
dtype = self ._baseline_prediction .dtype ,
1016
+ order = "F" ,
1013
1017
)
1014
1018
raw_predictions += self ._baseline_prediction
1015
1019
@@ -1693,7 +1697,7 @@ def predict_proba(self, X):
1693
1697
The class probabilities of the input samples.
1694
1698
"""
1695
1699
raw_predictions = self ._raw_predict (X )
1696
- return self ._loss .predict_proba (raw_predictions . T )
1700
+ return self ._loss .predict_proba (raw_predictions )
1697
1701
1698
1702
def staged_predict_proba (self , X ):
1699
1703
"""Predict class probabilities at each iteration.
@@ -1713,7 +1717,7 @@ def staged_predict_proba(self, X):
1713
1717
for each iteration.
1714
1718
"""
1715
1719
for raw_predictions in self ._staged_raw_predict (X ):
1716
- yield self ._loss .predict_proba (raw_predictions . T )
1720
+ yield self ._loss .predict_proba (raw_predictions )
1717
1721
1718
1722
def decision_function (self , X ):
1719
1723
"""Compute the decision function of ``X``.
0 commit comments