Code Monkey home page Code Monkey logo

Comments (2)

TobyRoseman avatar TobyRoseman commented on August 16, 2024

This is still an issue with coremltools 4.1, macOS 11.3 Beta and Scikit Learn 0.19.2.

from coremltools.

TobyRoseman avatar TobyRoseman commented on August 16, 2024

The following code now runs without assertions:

from sklearn.ensemble import GradientBoostingClassifier
from sklearn.datasets import load_boston
import numpy as np
import pandas as pd

from coremltools.converters import sklearn as skl_converter

args = {'max_leaf_nodes': None, 'min_samples_leaf': 1, 'min_samples_split': 2,
        'min_weight_fraction_leaf': 0.5, 'max_features': 1, 'max_depth': 1}

scikit_model = GradientBoostingClassifier(random_state = 1, **args)

scikit_data = load_boston()
X = scikit_data.data.astype('f').astype('d')

num_classes = 3
t = scikit_data.target
target = np.digitize(t, np.histogram(t, bins = num_classes - 1)[1]) - 1
scikit_model.fit(X, target)

coreml_model = skl_converter.convert(scikit_model, scikit_data.feature_names)

df = pd.DataFrame(X, columns=scikit_data.feature_names)

for i, row in df.iterrows():
    y_cm = coreml_model.predict(dict(row))['classProbability']
    y_sk = scikit_model.predict_proba([X[i]])
    for i in range(3):
        assert(np.isclose(y_cm[i], y_sk[0][i]))

This was likely fixed as the result of the work done to support the latest version of scikit-learn.

from coremltools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.