import{s as we,n as Te,o as he}from"../chunks/scheduler.5f3e6389.js";import{S as be,i as je,e as p,s as a,c as i,h as Ue,a as r,d as s,b as n,f as de,g as c,j as M,k as fe,l as We,m as l,n as m,t as o,o as y,p as u}from"../chunks/index.62df735e.js";import{C as Ie,H as Ze,E as $e}from"../chunks/MermaidChart.svelte_svelte_type_style_lang.e306bd5b.js";import{C as V}from"../chunks/CodeBlock.dc1e8be0.js";function ke(pe){let J,R,N,F,d,H,f,x,w,re="To run the scikit-learn examples make sure you have installed the following library:",z,T,G,h,ie='The metrics in <code>evaluate</code> can be easily integrated with an Scikit-Learn estimator or <a href="https://scikit-learn.org/stable/modules/generated/sklearn.pipeline.Pipeline.html#sklearn.pipeline.Pipeline" rel="nofollow">pipeline</a>.',Q,b,ce="However, these metrics require that we generate the predictions from the model. The predictions and labels from the estimators can be passed to <code>evaluate</code> mertics to compute the required values.",E,j,S,U,me='Load data from <a href="https://www.openml.org/d/40945" rel="nofollow">https://www.openml.org/d/40945</a>:',q,W,L,I,oe="Alternatively X and y can be obtained directly from the frame attribute:",A,Z,P,$,ye="We create the preprocessing pipelines for both numeric and categorical data. Note that pclass could either be treated as a categorical or numeric feature.",D,k,K,B,ue="Append classifier to preprocessing pipeline. Now we have a full prediction pipeline.",O,X,ee,g,Je="As <code>Evaluate</code> metrics use lists as inputs for references and predictions, we need to convert them to Python lists.",te,C,se,v,Me="You can use any suitable <code>evaluate</code> metric with the estimators as long as they are compatible with the task and predictions.",le,_,ae,Y,ne;return d=new Ie({props:{containerStyle:"float: right; margin-left: 10px; display: inline-flex; position: relative; z-index: 10;"}}),f=new Ze({props:{title:"Scikit-Learn",local:"scikit-learn",headingTag:"h1"}}),T=new V({props:{code:"cGlwJTIwaW5zdGFsbCUyMC1VJTIwc2Npa2l0LWxlYXJu",highlighted:"pip install -U scikit-learn",wrap:!1}}),j=new V({props:{code:"aW1wb3J0JTIwbnVtcHklMjBhcyUyMG5wJTBBbnAucmFuZG9tLnNlZWQoMCklMEFpbXBvcnQlMjBldmFsdWF0ZSUwQWZyb20lMjBza2xlYXJuLmNvbXBvc2UlMjBpbXBvcnQlMjBDb2x1bW5UcmFuc2Zvcm1lciUwQWZyb20lMjBza2xlYXJuLmRhdGFzZXRzJTIwaW1wb3J0JTIwZmV0Y2hfb3Blbm1sJTBBZnJvbSUyMHNrbGVhcm4ucGlwZWxpbmUlMjBpbXBvcnQlMjBQaXBlbGluZSUwQWZyb20lMjBza2xlYXJuLmltcHV0ZSUyMGltcG9ydCUyMFNpbXBsZUltcHV0ZXIlMEFmcm9tJTIwc2tsZWFybi5wcmVwcm9jZXNzaW5nJTIwaW1wb3J0JTIwU3RhbmRhcmRTY2FsZXIlMkMlMjBPbmVIb3RFbmNvZGVyJTBBZnJvbSUyMHNrbGVhcm4ubGluZWFyX21vZGVsJTIwaW1wb3J0JTIwTG9naXN0aWNSZWdyZXNzaW9uJTBBZnJvbSUyMHNrbGVhcm4ubW9kZWxfc2VsZWN0aW9uJTIwaW1wb3J0JTIwdHJhaW5fdGVzdF9zcGxpdA==",highlighted:`<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
np.random.seed(<span class="hljs-number">0</span>)
<span class="hljs-keyword">import</span> evaluate
<span class="hljs-keyword">from</span> sklearn.compose <span class="hljs-keyword">import</span> ColumnTransformer
<span class="hljs-keyword">from</span> sklearn.datasets <span class="hljs-keyword">import</span> fetch_openml
<span class="hljs-keyword">from</span> sklearn.pipeline <span class="hljs-keyword">import</span> Pipeline
<span class="hljs-keyword">from</span> sklearn.impute <span class="hljs-keyword">import</span> SimpleImputer
<span class="hljs-keyword">from</span> sklearn.preprocessing <span class="hljs-keyword">import</span> StandardScaler, OneHotEncoder
<span class="hljs-keyword">from</span> sklearn.linear_model <span class="hljs-keyword">import</span> LogisticRegression
<span class="hljs-keyword">from</span> sklearn.model_selection <span class="hljs-keyword">import</span> train_test_split`,wrap:!1}}),W=new V({props:{code:"WCUyQyUyMHklMjAlM0QlMjBmZXRjaF9vcGVubWwoJTIydGl0YW5pYyUyMiUyQyUyMHZlcnNpb24lM0QxJTJDJTIwYXNfZnJhbWUlM0RUcnVlJTJDJTIwcmV0dXJuX1hfeSUzRFRydWUp",highlighted:'X, y = fetch_openml(<span class="hljs-string">&quot;titanic&quot;</span>, version=<span class="hljs-number">1</span>, as_frame=<span class="hljs-literal">True</span>, return_X_y=<span class="hljs-literal">True</span>)',wrap:!1}}),Z=new V({props:{code:"WCUyMCUzRCUyMHRpdGFuaWMuZnJhbWUuZHJvcCgnc3Vydml2ZWQnJTJDJTIwYXhpcyUzRDEpJTBBeSUyMCUzRCUyMHRpdGFuaWMuZnJhbWUlNUInc3Vydml2ZWQnJTVE",highlighted:`X = titanic.frame.drop(<span class="hljs-string">&#x27;survived&#x27;</span>, axis=<span class="hljs-number">1</span>)
y = titanic.frame[<span class="hljs-string">&#x27;survived&#x27;</span>]`,wrap:!1}}),k=new V({props:{code:"bnVtZXJpY19mZWF0dXJlcyUyMCUzRCUyMCU1QiUyMmFnZSUyMiUyQyUyMCUyMmZhcmUlMjIlNUQlMEFudW1lcmljX3RyYW5zZm9ybWVyJTIwJTNEJTIwUGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwc3RlcHMlM0QlNUIoJTIyaW1wdXRlciUyMiUyQyUyMFNpbXBsZUltcHV0ZXIoc3RyYXRlZ3klM0QlMjJtZWRpYW4lMjIpKSUyQyUyMCglMjJzY2FsZXIlMjIlMkMlMjBTdGFuZGFyZFNjYWxlcigpKSU1RCUwQSklMEElMEFjYXRlZ29yaWNhbF9mZWF0dXJlcyUyMCUzRCUyMCU1QiUyMmVtYmFya2VkJTIyJTJDJTIwJTIyc2V4JTIyJTJDJTIwJTIycGNsYXNzJTIyJTVEJTBBY2F0ZWdvcmljYWxfdHJhbnNmb3JtZXIlMjAlM0QlMjBPbmVIb3RFbmNvZGVyKGhhbmRsZV91bmtub3duJTNEJTIyaWdub3JlJTIyKSUwQSUwQXByZXByb2Nlc3NvciUyMCUzRCUyMENvbHVtblRyYW5zZm9ybWVyKCUwQSUyMCUyMCUyMCUyMHRyYW5zZm9ybWVycyUzRCU1QiUwQSUyMCUyMCUyMCUyMCUyMCUyMCUyMCUyMCglMjJudW0lMjIlMkMlMjBudW1lcmljX3RyYW5zZm9ybWVyJTJDJTIwbnVtZXJpY19mZWF0dXJlcyklMkMlMEElMjAlMjAlMjAlMjAlMjAlMjAlMjAlMjAoJTIyY2F0JTIyJTJDJTIwY2F0ZWdvcmljYWxfdHJhbnNmb3JtZXIlMkMlMjBjYXRlZ29yaWNhbF9mZWF0dXJlcyklMkMlMEElMjAlMjAlMjAlMjAlNUQlMEEp",highlighted:`numeric_features = [<span class="hljs-string">&quot;age&quot;</span>, <span class="hljs-string">&quot;fare&quot;</span>]
numeric_transformer = Pipeline(
    steps=[(<span class="hljs-string">&quot;imputer&quot;</span>, SimpleImputer(strategy=<span class="hljs-string">&quot;median&quot;</span>)), (<span class="hljs-string">&quot;scaler&quot;</span>, StandardScaler())]
)

categorical_features = [<span class="hljs-string">&quot;embarked&quot;</span>, <span class="hljs-string">&quot;sex&quot;</span>, <span class="hljs-string">&quot;pclass&quot;</span>]
categorical_transformer = OneHotEncoder(handle_unknown=<span class="hljs-string">&quot;ignore&quot;</span>)

preprocessor = ColumnTransformer(
    transformers=[
        (<span class="hljs-string">&quot;num&quot;</span>, numeric_transformer, numeric_features),
        (<span class="hljs-string">&quot;cat&quot;</span>, categorical_transformer, categorical_features),
    ]
)`,wrap:!1}}),X=new V({props:{code:"Y2xmJTIwJTNEJTIwUGlwZWxpbmUoJTBBJTIwJTIwJTIwJTIwc3RlcHMlM0QlNUIoJTIycHJlcHJvY2Vzc29yJTIyJTJDJTIwcHJlcHJvY2Vzc29yKSUyQyUyMCglMjJjbGFzc2lmaWVyJTIyJTJDJTIwTG9naXN0aWNSZWdyZXNzaW9uKCkpJTVEJTBBKSUwQSUwQVhfdHJhaW4lMkMlMjBYX3Rlc3QlMkMlMjB5X3RyYWluJTJDJTIweV90ZXN0JTIwJTNEJTIwdHJhaW5fdGVzdF9zcGxpdChYJTJDJTIweSUyQyUyMHRlc3Rfc2l6ZSUzRDAuMiUyQyUyMHJhbmRvbV9zdGF0ZSUzRDApJTBBJTBBY2xmLmZpdChYX3RyYWluJTJDJTIweV90cmFpbiklMEF5X3ByZWQlMjAlM0QlMjBjbGYucHJlZGljdChYX3Rlc3Qp",highlighted:`clf = Pipeline(
    steps=[(<span class="hljs-string">&quot;preprocessor&quot;</span>, preprocessor), (<span class="hljs-string">&quot;classifier&quot;</span>, LogisticRegression())]
)

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=<span class="hljs-number">0.2</span>, random_state=<span class="hljs-number">0</span>)

clf.fit(X_train, y_train)
y_pred = clf.predict(X_test)`,wrap:!1}}),C=new V({props:{code:"JTIzJTIwRXZhbHVhdGUlMjBtZXRyaWNzJTIwYWNjZXB0JTIwbGlzdHMlMjBhcyUyMGlucHV0cyUyMGZvciUyMHZhbHVlcyUyMG9mJTIwcmVmZXJlbmNlcyUyMGFuZCUyMHByZWRpY3Rpb25zJTBBJTBBeV90ZXN0JTIwJTNEJTIweV90ZXN0LnRvbGlzdCgpJTBBeV9wcmVkJTIwJTNEJTIweV9wcmVkLnRvbGlzdCgpJTBBJTBBJTIzJTIwQWNjdXJhY3klMEElMEFhY2N1cmFjeV9tZXRyaWMlMjAlM0QlMjBldmFsdWF0ZS5sb2FkKCUyMmFjY3VyYWN5JTIyKSUwQWFjY3VyYWN5JTIwJTNEJTIwYWNjdXJhY3lfbWV0cmljLmNvbXB1dGUocmVmZXJlbmNlcyUzRHlfdGVzdCUyQyUyMHByZWRpY3Rpb25zJTNEeV9wcmVkKSUwQXByaW50KCUyMkFjY3VyYWN5JTNBJTIyJTJDJTIwYWNjdXJhY3kpJTBBJTIzJTIwQWNjdXJhY3klM0ElMjAwLjc5",highlighted:`<span class="hljs-comment"># Evaluate metrics accept lists as inputs for values of references and predictions</span>

y_test = y_test.tolist()
y_pred = y_pred.tolist()

<span class="hljs-comment"># Accuracy</span>

accuracy_metric = evaluate.load(<span class="hljs-string">&quot;accuracy&quot;</span>)
accuracy = accuracy_metric.compute(references=y_test, predictions=y_pred)
<span class="hljs-built_in">print</span>(<span class="hljs-string">&quot;Accuracy:&quot;</span>, accuracy)
<span class="hljs-comment"># Accuracy: 0.79</span>`,wrap:!1}}),_=new $e({props:{source:"https://github.com/huggingface/evaluate/blob/main/docs/source/sklearn_integrations.mdx"}}),{c(){J=p("meta"),R=a(),N=p("p"),F=a(),i(d.$$.fragment),H=a(),i(f.$$.fragment),x=a(),w=p("p"),w.textContent=re,z=a(),i(T.$$.fragment),G=a(),h=p("p"),h.innerHTML=ie,Q=a(),b=p("p"),b.innerHTML=ce,E=a(),i(j.$$.fragment),S=a(),U=p("p"),U.innerHTML=me,q=a(),i(W.$$.fragment),L=a(),I=p("p"),I.textContent=oe,A=a(),i(Z.$$.fragment),P=a(),$=p("p"),$.textContent=ye,D=a(),i(k.$$.fragment),K=a(),B=p("p"),B.textContent=ue,O=a(),i(X.$$.fragment),ee=a(),g=p("p"),g.innerHTML=Je,te=a(),i(C.$$.fragment),se=a(),v=p("p"),v.innerHTML=Me,le=a(),i(_.$$.fragment),ae=a(),Y=p("p"),this.h()},l(e){const t=Ue("svelte-u9bgzb",document.head);J=r(t,"META",{name:!0,content:!0}),t.forEach(s),R=n(e),N=r(e,"P",{}),de(N).forEach(s),F=n(e),c(d.$$.fragment,e),H=n(e),c(f.$$.fragment,e),x=n(e),w=r(e,"P",{"data-svelte-h":!0}),M(w)!=="svelte-pb1681"&&(w.textContent=re),z=n(e),c(T.$$.fragment,e),G=n(e),h=r(e,"P",{"data-svelte-h":!0}),M(h)!=="svelte-k0enqt"&&(h.innerHTML=ie),Q=n(e),b=r(e,"P",{"data-svelte-h":!0}),M(b)!=="svelte-13ps3um"&&(b.innerHTML=ce),E=n(e),c(j.$$.fragment,e),S=n(e),U=r(e,"P",{"data-svelte-h":!0}),M(U)!=="svelte-1po732b"&&(U.innerHTML=me),q=n(e),c(W.$$.fragment,e),L=n(e),I=r(e,"P",{"data-svelte-h":!0}),M(I)!=="svelte-mki1gd"&&(I.textContent=oe),A=n(e),c(Z.$$.fragment,e),P=n(e),$=r(e,"P",{"data-svelte-h":!0}),M($)!=="svelte-1vob52e"&&($.textContent=ye),D=n(e),c(k.$$.fragment,e),K=n(e),B=r(e,"P",{"data-svelte-h":!0}),M(B)!=="svelte-4wccpt"&&(B.textContent=ue),O=n(e),c(X.$$.fragment,e),ee=n(e),g=r(e,"P",{"data-svelte-h":!0}),M(g)!=="svelte-4ry0to"&&(g.innerHTML=Je),te=n(e),c(C.$$.fragment,e),se=n(e),v=r(e,"P",{"data-svelte-h":!0}),M(v)!=="svelte-1lzytmq"&&(v.innerHTML=Me),le=n(e),c(_.$$.fragment,e),ae=n(e),Y=r(e,"P",{}),de(Y).forEach(s),this.h()},h(){fe(J,"name","hf:doc:metadata"),fe(J,"content",Be)},m(e,t){We(document.head,J),l(e,R,t),l(e,N,t),l(e,F,t),m(d,e,t),l(e,H,t),m(f,e,t),l(e,x,t),l(e,w,t),l(e,z,t),m(T,e,t),l(e,G,t),l(e,h,t),l(e,Q,t),l(e,b,t),l(e,E,t),m(j,e,t),l(e,S,t),l(e,U,t),l(e,q,t),m(W,e,t),l(e,L,t),l(e,I,t),l(e,A,t),m(Z,e,t),l(e,P,t),l(e,$,t),l(e,D,t),m(k,e,t),l(e,K,t),l(e,B,t),l(e,O,t),m(X,e,t),l(e,ee,t),l(e,g,t),l(e,te,t),m(C,e,t),l(e,se,t),l(e,v,t),l(e,le,t),m(_,e,t),l(e,ae,t),l(e,Y,t),ne=!0},p:Te,i(e){ne||(o(d.$$.fragment,e),o(f.$$.fragment,e),o(T.$$.fragment,e),o(j.$$.fragment,e),o(W.$$.fragment,e),o(Z.$$.fragment,e),o(k.$$.fragment,e),o(X.$$.fragment,e),o(C.$$.fragment,e),o(_.$$.fragment,e),ne=!0)},o(e){y(d.$$.fragment,e),y(f.$$.fragment,e),y(T.$$.fragment,e),y(j.$$.fragment,e),y(W.$$.fragment,e),y(Z.$$.fragment,e),y(k.$$.fragment,e),y(X.$$.fragment,e),y(C.$$.fragment,e),y(_.$$.fragment,e),ne=!1},d(e){e&&(s(R),s(N),s(F),s(H),s(x),s(w),s(z),s(G),s(h),s(Q),s(b),s(E),s(S),s(U),s(q),s(L),s(I),s(A),s(P),s($),s(D),s(K),s(B),s(O),s(ee),s(g),s(te),s(se),s(v),s(le),s(ae),s(Y)),s(J),u(d,e),u(f,e),u(T,e),u(j,e),u(W,e),u(Z,e),u(k,e),u(X,e),u(C,e),u(_,e)}}}const Be='{"title":"Scikit-Learn","local":"scikit-learn","sections":[],"depth":1}';function Xe(pe){return he(()=>{new URLSearchParams(window.location.search).get("fw")}),[]}class Ve extends be{constructor(J){super(),je(this,J,Xe,ke,we,{})}}export{Ve as component};
