Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scikit-learn
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ian Johnson
scikit-learn
Commits
b45d282c
Commit
b45d282c
authored
14 years ago
by
Olivier Grisel
Browse files
Options
Downloads
Plain Diff
Merge branch 'master' of github.com:scikit-learn/scikit-learn
parents
80bfde5b
d8620ed4
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
scikits/learn/svm/src/liblinear/liblinear_helper.c
+17
-8
17 additions, 8 deletions
scikits/learn/svm/src/liblinear/liblinear_helper.c
scikits/learn/tests/test_grid_search.py
+1
-1
1 addition, 1 deletion
scikits/learn/tests/test_grid_search.py
with
18 additions
and
9 deletions
scikits/learn/svm/src/liblinear/liblinear_helper.c
+
17
−
8
View file @
b45d282c
...
...
@@ -42,7 +42,7 @@ struct feature_node **dense_to_sparse (double *x, npy_intp *dims, double bias)
/* set bias element */
if
(
bias
>
0
)
{
T
->
value
=
1
.
0
;
T
->
value
=
bias
;
T
->
index
=
j
;
++
T
;
}
...
...
@@ -72,7 +72,7 @@ struct feature_node **csr_to_sparse (double *values, npy_intp *shape_indices,
{
struct
feature_node
**
sparse
,
*
temp
;
int
i
,
j
=
0
,
k
=
0
,
n
;
sparse
=
(
struct
feature_node
**
)
malloc
(
shape_indptr
[
0
]
*
sizeof
(
struct
feature_node
*
));
sparse
=
(
struct
feature_node
**
)
malloc
(
(
shape_indptr
[
0
]
-
1
)
*
sizeof
(
struct
feature_node
*
));
for
(
i
=
0
;
i
<
shape_indptr
[
0
]
-
1
;
++
i
)
{
n
=
indptr
[
i
+
1
]
-
indptr
[
i
];
/* count elements in row i */
...
...
@@ -83,12 +83,14 @@ struct feature_node **csr_to_sparse (double *values, npy_intp *shape_indices,
temp
[
j
].
index
=
indices
[
k
]
+
1
;
/* libsvm uses 1-based indexing */
++
k
;
}
/* set sentinel */
if
(
bias
>
0
)
{
temp
[
j
].
value
=
1
.
0
;
temp
[
j
].
index
=
(
int
)
n_features
+
1
;
temp
[
j
].
value
=
bias
;
temp
[
j
].
index
=
n_features
+
1
;
++
j
;
}
/* set sentinel */
temp
[
j
].
index
=
-
1
;
}
...
...
@@ -98,7 +100,7 @@ struct feature_node **csr_to_sparse (double *values, npy_intp *shape_indices,
struct
problem
*
set_problem
(
char
*
X
,
char
*
Y
,
npy_intp
*
dims
,
double
bias
)
{
struct
problem
*
problem
;
/* not performant
,
but
its the
simple
r way
*/
/* not performant but simple */
problem
=
(
struct
problem
*
)
malloc
(
sizeof
(
struct
problem
));
if
(
problem
==
NULL
)
return
NULL
;
problem
->
l
=
(
int
)
dims
[
0
];
...
...
@@ -108,13 +110,15 @@ struct problem * set_problem(char *X,char *Y, npy_intp *dims, double bias)
}
else
{
problem
->
n
=
(
int
)
dims
[
1
];
}
problem
->
y
=
(
int
*
)
Y
;
problem
->
x
=
dense_to_sparse
((
double
*
)
X
,
dims
,
bias
);
/* TODO: free */
problem
->
x
=
dense_to_sparse
((
double
*
)
X
,
dims
,
bias
);
problem
->
bias
=
bias
;
if
(
problem
->
x
==
NULL
)
{
free
(
problem
);
return
NULL
;
}
return
problem
;
}
...
...
@@ -126,18 +130,23 @@ struct problem * csr_set_problem (char *values, npy_intp *n_indices,
problem
=
(
struct
problem
*
)
malloc
(
sizeof
(
struct
problem
));
if
(
problem
==
NULL
)
return
NULL
;
problem
->
l
=
(
int
)
n_indptr
[
0
]
-
1
;
if
(
bias
>
0
){
problem
->
n
=
(
int
)
n_features
+
1
;
}
else
{
problem
->
n
=
(
int
)
n_features
;
}
problem
->
y
=
(
int
*
)
Y
;
problem
->
x
=
csr_to_sparse
((
double
*
)
values
,
n_indices
,
(
int
*
)
indices
,
n_indptr
,
(
int
*
)
indptr
,
bias
,
n_features
);
problem
->
bias
=
bias
;
if
(
problem
->
x
==
NULL
)
{
free
(
problem
);
return
NULL
;
}
return
problem
;
}
...
...
This diff is collapsed.
Click to expand it.
scikits/learn/tests/test_grid_search.py
+
1
−
1
View file @
b45d282c
...
...
@@ -64,7 +64,7 @@ def test_grid_search_sparse():
y_pred2
=
cv
.
predict
(
X_
[
180
:])
C2
=
cv
.
best_estimator
.
C
assert
_array_equal
(
y_pred
,
y_pred2
)
assert
np
.
mean
(
y_pred
==
y_pred2
)
>=
.
9
assert_equal
(
C
,
C2
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment